正则表达式搜索两个字符串之间的内容的字符串 [英] regex search a string for contents between two strings
问题描述
我正在尝试在字符串中搜索文本,我知道字符串如何启动,我知道字符串的结尾,我想返回字符串之间的所有文本,包括开始和结束。
开始搜索= [{lx:
结束搜索= }]
ie
[{lx: variablehere }]
到目前为止我已尝试过
/ ^ \ [\ {lx:(*?)\} \ ] /;
和
/(\ [\ { LX:)(*)(\} \])/;
但是没有真正的利用...任何人都可以帮助?
非常感谢
你可能会错误地相信 *
是通配符。使用期限(。
),你会很好。
另外,你确定要规定零个或多个?如果必须是一个值,请使用+(一个或多个)。
Javascript:
$ {$ {$ {$ {$} $$$ {$$$ )\} \] /);
I am trying my upmost best to get my head around regex, however not having too much luck.
I am trying to search within a string for text, I know how the string starts, and i know how the string ends, I want to return ALL the text inbetween the string including the start and end.
Start search = [{"lx":
End search = }]
i.e
[{"lx":variablehere}]
So far I have tried
/^\[\{"lx":(*?)\}\]/;
and
/(\[\{"lx":)(*)(\}\])/;
But to no real avail... can anyone assist?
Many thanks
You're probably making the mistake of believing the *
is a wildcard. Use the period (.
) instead and you'll be fine.
Also, are you sure you want to stipulate zero or more? If there must be a value, use + (one or more).
Javascript:
'[{"lx":variablehere}]'.match(/^\[\{"lx":(.+?)\}\]/);
这篇关于正则表达式搜索两个字符串之间的内容的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!