我正在使用 JAVA,并且想要替换美元符号之间的每个文本实例。例如:
1st equation $\frac{1}{\mu -1}\frac{2\pi }{\lambda }x$
2nd equation $90^{^{0}}$
3rd equation $\frac{\mu t}{2}$
4th equation $2\mu tcosr=\frac{\left ( 2n+1 \right ) \lambda}{2}$
替换为这个
1st equation <img src="http://latex.codecogs.com/gif.latex?$\frac{1}{\mu -1}\frac{2\pi }{\lambda }x$ " border="0"/>
2nd equation <img src="http://latex.codecogs.com/gif.latex?$90^{^{0}}$" border="0"/>
3rd equation <img src="http://latex.codecogs.com/gif.latex?$\frac{\mu t}{2}$" border="0"/>
4th equation <img src="http://latex.codecogs.com/gif.latex?$2\mu tcosr=\frac{\left ( 2n+1 \right ) \lambda}{2}$" border="0"/>
我在 stackoverflow.com 上搜索并找到了与 C#.NET 类似的内容正则表达式替换美元符号之间的文本 https://stackoverflow.com/questions/7666305/regex-to-replace-text-between-dollar-signs
我相信它会是这样的......
myString.replaceAll("\\$[^$]*\\$",
"<img src=\"http://latex.codecogs.com/gif.latex?$0 \" border=\"0\"/>"
The $0
替换字符串中的内容应与搜索正则表达式中的捕获组匹配...
字符串.replaceAll http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29
匹配器.replaceAll http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#replaceAll%28java.lang.String%29
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)