作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
为什么这个正则表达式在 Python 中有效但在 Ruby 中无效:
/(?<!([0-1\b][0-9]|[2][0-3]))/
很高兴听到解释以及如何在 Ruby 中绕过它
编辑整行代码:
re.sub(r'(?<!([0-1\b][0-9]|[2][0-3])):(?!([0-5][0-9])((?i)(am)|(pm)|(a\.m)|(p\.m)|(a\.m\.)|(p\.m\.))?\b)' , ':\n' , s)
基本上,当有冒号而不是时间时,我会尝试添加 '\n'
。
最佳答案
Ruby 正则表达式引擎不允许在 look behinds 中捕获组。如果需要分组,可以使用非捕获组 (?:)
:
[8] pry(main)> /(?<!(:?[0-1\b][0-9]|[2][0-3]))/
SyntaxError: (eval):2: invalid pattern in look-behind: /(?<!(:?[0-1\b][0-9]|[2][0-3]))/
[8] pry(main)> /(?<!(?:[0-1\b][0-9]|[2][0-3]))/
=> /(?<!(?:[0-1\b][0-9]|[2][0-3]))/
(?<!subexp) negative look-behind
Subexp of look-behind must be fixed-width.
But top-level alternatives can be of various lengths.
ex. (?<=a|bc) is OK. (?<=aaa(?:b|cd)) is not allowed.
In negative look-behind, capturing group isn't allowed,
but non-capturing group (?:) is allowed.
学习自this answer .
关于python - 后视模式无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57102938/
我正在尝试获得一个按钮,按下该按钮时会改变颜色。当再次按下时,它应该变回原来的颜色。我究竟做错了什么? 我的模板中的按钮: export default { data: {
我是一名优秀的程序员,十分优秀!