- #1
Simfish
Gold Member
- 823
- 2
I know that there's probably a way to do this with regexp, but I don't know regexp (yet). So does anyone have any tips on how to create the regexp expression for it? (and what other ways are there?)
Simfish said:I know that there's probably a way to do this with regexp, but I don't know regexp (yet). So does anyone have any tips on how to create the regexp expression for it? (and what other ways are there?)
$string =~ s/\$([^$]*)\$/\[xet\]$1\[\/xet\]/gs;
I paid $3 to Tim to get the answer $x^2$, but Bob only charged $2.
I paid [xet]3 to Tim to get the answer [/xet]x^2[xet], but Bob only charged [/xet]2.
I paid $3 to Tim to get the answer [xet]x^2[/xet], but Bob only charged $2.
$string =~ s/\$([^$\s]*)\$/\[xet\]$1\[\/xet\]/gs;
davee123 said:Yeah, Perl-wise, I think I'd do:
Code:$string =~ s/\$([^$]*)\$/\[xet\]$1\[\/xet\]/gs;
As pointed out, this won't always work if there are any extra $ signs floating around.
$string =~ s/(?<!\\)\$([^\$]*[^\\])\$/\[xet\]$1\[\/xet\]/gs;
perl -pe 's/(?<!\\)\$([^\$]*[^\\])\$/\[xet\]$1\[\/xet\]/gs;'
Simfish said:Thanks for all the replies, everyone! :) Based on the input, I've created my own regexp expression (for the JGSoft software that I use). Which is basically this:
search: \$([^$]*)\$
replace: [xet]$1[/xet]
===
It actually might be helpful to put sample regexp expressions on the PF Help threads about LaTeX (since it makes it much easier for people to convert their tags from their documents to the LaTeX demanded by PF).
Coin said:Borek, thanks, is that documented somewhere?
No, simply replacing the $$ tags with [tex][/tex] will not work as it may cause formatting issues. A more systematic approach is needed.
Yes, there are several programs and scripts available online that can help with this conversion. However, it is important to double-check the converted equations for accuracy.
Some basic understanding of coding and regular expressions may be helpful, but there are also user-friendly tools available for those without extensive technical knowledge.
One downside is that not all platforms and software support the [tex][/tex] format, so the equations may not be visible to all users. Additionally, the conversion process may not be 100% accurate.
Yes, the method used for converting $$ tags to [tex][/tex] can also be applied to other types of mathematical tags, such as \( \) and \[ \]. However, it is important to test and make sure the converted equations are correct.