I would like to replace all strings that are enclosed by -
into strings enclosed by ~
, but not if this string again is enclosed by *
.
As an example, this string...
The -quick- *brown -f-ox* jumps.
...should become...
The ~quick~ *brown -f-ox* jumps.
We see -
is only replaced if it is not within *<here>*
.
My javascript-regex for now (which takes no care whether it is enclosed by *
or not):
var message = source.replace(/-(.[^-]+?)-/g, "~$1~");
Edit: Note that it might be the case that there is an odd number of *
s.
The *-quick-* brown * -f-ox* jumps*.
Which-
characters should be replaced and why?*
is not replaced. It is printed as*
y
flag, said to be proposed for ECMAScript 6 would help a lot: developer.mozilla.org/en-US/docs/JavaScript/Reference/…