正则表达式不匹配行的开头/结尾
我希望正则表达式仅匹配 "
- 不出现在行首或行首空白之后的
- "不出现在行尾或末尾空白之前的 "行
我想我需要使用lookbehind和lookahead
所以匹配“in
zfgjhsgaf jhsa gd " gjhygf" hgf
但不” 。
"gjhgjkgjhgjhgkk"
"dfsdfsdf"
I would like a regular expression to match only " that
- don't come at the start of a line or after white space at the start of a line
- don't come at the end of a line or before white space at the end of a line
I guess I need to use lookbehind and lookahead.
So matches the " in
zfgjhsgaf jhsa gd " gjhygf" hgf
But not in
"gjhgjkgjhgjhgkk"
"dfsdfsdf"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于 Eclipse,尝试通过此正则表达式查找:
并替换为:
For Eclipse, try finding by this regex:
And replacing with:
请参阅此处
at Regexr
它不适用于行开头之后的空格。正如 BoltClock 提到的,只有少数引擎支持可变长度后视(我只知道 .net)。
如果您使用支持它的正则表达式,则可以使用
perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind
See this here
at Regexr
It works not for the whitespace after beginning of the line. As BoltClock mentioned, variable length look behind is supported only by few engines (I know only .net).
If you use a regex that support it, you can use
A good documentation for look ahead/behind is here in the perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind
它支持匹配 ' "foo"bar" ' 假设这是你想要找到的东西。
哦,它仅在设置 $1 时匹配
Which supports matching ' "foo"bar" ' assuming that is something that you want to find.
Oh, and it only matches if $1 is set
这个应该可以
This one should work
我认为这已经足够表达了:
I think whis re is expressive enougth :