I'm trying to wrap any content between two characters (in my case, a dollar sign $
) in a custom tag (in this case, math
) using regex. I've managed to make it work, but recently I encountered an edge case: for some reason, it doesn't work for a single-character content.
Here's my pattern: \$(\S[^\$]+\S)\$
, replacing with <math equation="$1">$1</math>
.
I've tested it for the string This is my $f(x) = x$ function, where $x$ is a natural number.
, getting the following ouput: This is my <math eq="f(x) = x">f(x) = x</math> function, where $x$ is a natural number.
. Notice that $x$
is getting ignored.
Thanks in advance.
It actually doesn't match anything with less than three characters. I believe your regex should be \$([^\$]+)\$
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments