Java - RegEx to replace text between dollar signs

前端 未结 2 391
一生所求
一生所求 2021-01-26 23:01

I am using JAVA and want to replace every instance of text between dollar signs. For example:

1st equation $\\frac{1}{\\mu -1}\\frac{2\\pi }{\\lambda }x$ 
2nd eq         


        
相关标签:
2条回答
  • 2021-01-26 23:38

    I believe it would be something like this...

    myString.replaceAll("\\$[^$]*\\$", 
         "<img src=\"http://latex.codecogs.com/gif.latex?$0 \" border=\"0\"/>"
    

    The $0 in the replacement string should match the capturing group in the search regex per...

    String.replaceAll

    Matcher.replaceAll

    0 讨论(0)
  • 2021-01-26 23:45

    The regex used in C# is the same for Java, except that you need to double escape $.

    "\\$([^\\$]*)\\$"
    
    0 讨论(0)
提交回复
热议问题