[英]javascript Regular Expression and Replace
how can i replace 我该如何更换
<em>Rs</em> 154,451. Hello world
to 至
<b>Rs 154,451</b>. Hello world
via JavaScript Regular Expression. 通过JavaScript正则表达式。
/<em>Rs<\/em> [0-9,]*/ig
is regular expression to find <em>Rs</em> 154,451
是查找
<em>Rs</em> 154,451
正则表达式
You can use ()
to capture a match and later use it in the replace: 您可以使用
()
捕获匹配项,然后在替换中使用它:
var s = "<em>Rs</em> 154,451. Hello world";
s.replace(/<em>Rs<\/em>([^.]+)/, '<b>Rs$1</b>')
Try this one: 试试这个:
myString = "<em>Rs</em> 154,451. Hello world";
output = myString.replace(/<em>Rs<\/em>\s*(\d+(?:,\d+)?)/g, "<b>Rs $1</b>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.