开发者

How to create regex pattern - value between "$" character

How to create regex pattern - value between "$" character.

e.g. String: " <tag key = $value$ />开发者_如何学编程; "

I want get "value" string from this...


If I understand correctly, you're trying to get a string that is located between 2 dollar signs. The code (perl) should look similar to:

if ($str =~ /\$(\w)\$/)
   $substr = $1;  

of course, you can replace the \w sign with a pattern of your choosing...

EDIT:

if ($str =~ /\<tag key \= \$(\w)\$ \/\>/)
  $substr =$1;


From my understanding you are looking to return exact word from a string. i.e return is from this island is beautiful instead of returning this, island and is

If I am correct explaining your problem the regex you are looking for will be \bis\b

For more information visit this link, http://www.regular-expressions.info/wordboundaries.html


In javascript, you could is the following:

var theString = '<tag key = $value$ />';

var newString = theString.replace(/^.*\$(.*?)\$.*$/, '$1');

Or you could use the RegExp object to do something like:

var pattern=new RegExp('\\$(.*?)\\$');

var newString = pattern.exec(theString )[1];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜