regex - Scala Regex Positive and Negative Look Behind at the same time
问题描述
I have an input string like this
val input = """["abc:def&ghi:jkl"]"""
I want to extract abc
and ghi
So I wrote this regex which works
val regex = """(?<=["&])(\w+)(?=[:])""".r
regex.findAllIn(input).foreach(println)
So basically I have a look ahead for :
and a look behind for either "
or &
.
So far so good. But now I have an input like this
val input = """["abc:de_&_f:xyz&ghi:jkl"]"""
it matches
abc
_f
ghi
I want to change the logic of my regex to say.
Match a \w+
when look ahead is true for :
and look behind is true for &
and false for _&_
So I want to use the positive and negative look behind at the same time. How do I do that?
解决方案
推荐阅读
- android - 令人遗憾的 GPU 渲染配置文件只有光标闪烁
- swift - IOS 图表/MPAndroidChart。轴高
- html - 从 HTML 调用打字稿文件中的函数不显示返回变量
- python - Django - 登录的用户未在 admin.py 中填充
- kubernetes - 如何使用模板生成器生成 kubernetes yaml 文件?
- python-3.x - 如何循环从 python-docx 获得的列表列表,其中每个列表都是一个表,并将表写入单独的工作表
- amazon-web-services - 如何从限制对特定 API 端点访问的 lambda 授权方生成 IAM 策略?
- sas - 期待 SAS 中的算术运算符?
- c# - 将实体分页类映射到 dto 分页类
- python - 无法播放 IBM Watson 的 TTS(文本到语音)生成的 WAV 文件