Regex pattern not working with single characters

Gelu

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.

IndevSmiles

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.

edited at
0

Comments

0 comments
Login to comment

Related