1

how can i replace

<em>Rs</em> 154,451. Hello world   

to

<b>Rs 154,451</b>. Hello world

via JavaScript Regular Expression.

/<em>Rs<\/em> [0-9,]*/ig

is regular expression to find <em>Rs</em> 154,451

2 Answers 2

1

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>')
Sign up to request clarification or add additional context in comments.

Comments

1

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>");

1 Comment

it is returning Rs $1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.