正则表达式
我有一个与此类似的字符串:
Hi, <<\name>> <<\surname>>, this is an example <<\test>>.
我用什么正则表达式来匹配并分割该字符串:
"Hi, "
<<\name>>
" "
<<\surname>>
", this is an example "
<<\test>>
"."
我尝试了这个: (<<\*.*?>>)|(>> *.*?<<)
,但不起作用。有可能吗? 谢谢。
i have a string similar to this one:
Hi, <<\name>> <<\surname>>, this is an example <<\test>>.
I what a regex that match and split this string in:
"Hi, "
<<\name>>
" "
<<\surname>>
", this is an example "
<<\test>>
"."
I tried this one: (<<\*.*?>>)|(>>*.*?<<)
, but doesn't work. It's possible?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用此表达式(它使用正前瞻和正后瞻):
它匹配由
<<
和>>
符号包围的字符串,这些字符串位于这些符号之间从开始到<<
以及从>>
到结束的符号和字符串。您可以在 ideone 上找到
C#
示例。You could use this expression (it uses positive lookaheads and positive lookbehinds):
it matches strings surrounded by
<<
and>>
symbols, strings which are between these symbols and strings from the begin to<<
and to the end from>>
.You could find a
C#
example on ideone.使用 str_replace
use str_replace