如何通过JavaScript正则表达式替换JavaScript正则表达式和替换
<em>Rs</em> 154,451. Hello world
到
<b>Rs 154,451</b>. Hello world
。
/<em>Rs<\/em> [0-9,]*/ig
是正则表达式找到<em>Rs</em> 154,451
如何通过JavaScript正则表达式替换JavaScript正则表达式和替换
<em>Rs</em> 154,451. Hello world
到
<b>Rs 154,451</b>. Hello world
。
/<em>Rs<\/em> [0-9,]*/ig
是正则表达式找到<em>Rs</em> 154,451
您可以使用()
捕捉比赛,后来在用它替换:
var s = "<em>Rs</em> 154,451. Hello world";
s.replace(/<em>Rs<\/em>([^.]+)/, '<b>Rs$1</b>')
试试这个:
myString = "<em>Rs</em> 154,451. Hello world";
output = myString.replace(/<em>Rs<\/em>\s*(\d+(?:,\d+)?)/g, "<b>Rs $1</b>");
它回来卢比$ 1 –
感谢它的工作 –
这个回报卢比$ 1 –