正则表达式解析器和自定义转义字符
我有一个字符串,我想从该字符串的开头和结尾中挑选出带有加号的子字符串。
示例:
text +name+ filler with /+ sign +b+ bold text +/b+
我想挑选 +name+
+b+
和 +/b+
,但我当前的正则表达式会处理 + 符号 +
作为可能的值”
这是我正在使用的正则表达式 \+[\-@\w\s\d\/\!]*\+
我已经尝试过在前面添加一个[^/]
,但这会添加 +
之前的任何字符,并且无法处理 +n++b+
我正在尝试找出环视和环视,只是不知道如何应用它。
I have a string that I'd like to pick out sub-strings from that start and end with a plus sign.
example:
text +name+ filler with /+ sign +b+ bold text +/b+
I'd like to pick out the +name+
+b+
and the+/b+
, but my current regex would treat + sign +
as a possible value"
this is the regex I am using \+[\-@\w\s\d\/\!]*\+
I've tried adding a [^/]
in front, but that adds whatever character there was before the +
and cannot deal with +n++b+
I'm trying to figure out the lookaround and lookbehind, just not sure how to apply it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
负向回顾看起来像这样
(?。仅当前一个字符不是
/
时才匹配。示例:
注意:
/
字符作为正则表达式的分隔符,则可能必须转义该字符。The negative lookbehind looks like this
(?<!/)
. This only matches if the previous character is not a/
.Example:
Note:
/
if you are using that character as the delimiter for your regular expression.