Viliami Viliami - 1 year ago 88
Javascript Question

Check if string contains character within a group

I've tried this (using javascript):

"[a][\"][\"2]".replace(/(\[)[\"](\])/g, "$1replaced$2")
//checks for double quote between [ and ]

and this is returned


So the current regex only checks for a single double-quote character("), how do I check if a string contains a
character within the matched group (between


So the outcome I'm looking for is changing from this:




basically replacing all double-quote characters within

Answer Source

Here's what you want

"[a][\"][\"2][asdf\"1234]".replace(/(\[)([^\]]*)(\])/g, function (match, leftBr, guts, rightBr) {
  return leftBr + guts.replace(/\"/g, "replaced") + rightBr;

It grabs the guts of every bracket group and removes the quotes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download