Silly question, but I do not know how to find (2000) into a regular expression and replace it with [2000]
You can do:
str.replace(/\((\d+)\)/g, "[$1]");
Regex used: \((\d+)\)
( and ) are special char in regex
used for grouping, to match literal
( ), you need to escape them as
\( \)\d is short for a digit. \d+
means one or more digits.( ) is to group and remember the
number. The remembered number will
later be used in replacement.g for global replacement. Mean
every occurrence of the patten in the
string will be replaced.$1 is the number between (
)that was grouped and remembered./ / are the regex delimiters.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With