Following regex replaces " >" or " > " or "> "
character with "/"
.
tempKeyword = tempKeyword.replace(/( > )|( >)|(> )/g,'/');
How can I make this better?
Thanks!
Following regex replaces " >" or " > " or "> "
character with "/"
.
tempKeyword = tempKeyword.replace(/( > )|( >)|(> )/g,'/');
How can I make this better?
Thanks!
Have a try with this one:
tempKeyword = tempKeyword.replace(/\s*>\s*/g,'/');
Edit 2 according to comment below:
tempKeyword = tempKeyword.replace(/(?:^|\S+\s)>(?:\s\S+|$)/g,'/');
You can make your regular expression like so:
/ ?> ?/g
What we do here is saying if you find > with 0 or 1 space before then match. (the ? operator stands for 0 or 1)