I am receiving messages which have underscores:
However, when these messages are formatted by our HTML wire formatter we receive
them with backslashes infront of the underscores:
I created the following regex to capture the backslashes and remove them so the
text tokenizes correctly:
However, there is an edge case of when a user italicizes text. When the user
utalicizes text, we receive the messages with NO backslashes but with
underscores - and we want to remove the underscores. This is what the received
text looks like:
I am trying to design a regex which matches a backslash followed by an
underscore and then replaces the backslash (but not the underscore) OR if there
is only a underscore with no bachslash, it only matches the underscore.
I tried to implement this using lookaheads:
var regex = /\\(?=_)|_/g;
var string = '\\_omgitworks\\_'
But it is removing the backslash AND the underscore instead of just the
underscore. Are there any nuances to lookaheads that I am overlooking?