JQuery replace text between parentheses
3 answers
You can use regex - this is not jQuery, but part of JavaScript:
var s = "hello (there)";
s = s.replace(/\(.*?\)/, 'world');
For more than one pair:
s = s.replace(/\(.*?\)/g, 'world');
It won't work if there are more parentheses in the parentheses, mind you; Another option - use /\(.*\)/
for capturing from first to last - "a (b (c) d)"
→ "a world"
, but the same goes for "a (b) c (d)"
.
+11
a source to share
Use regular expressions instead of using JQuery: http://www.w3schools.com/jsref/jsref_replace.asp
This is the second example where you can specify a regex to target (s) and then replace the inner content ... something like /(.+)/i how regex should work.
NTN.
+1
a source to share