Java 如何使用正则表达式在字符串中查找Latex表达式
其他人告诉我一个python模式:Java 如何使用正则表达式在字符串中查找Latex表达式,java,regex,latex,Java,Regex,Latex,其他人告诉我一个python模式: private static final String TEXT = "this a test 1: $\\$$,test 2: $\\underline{\\rm defund}$, test 3:$$\\underline{\\rm defund}$$"; 但是我在android中使用它,Java不支持express模式。谁能为我写一个Java模式,或者给我一些提示?在Java中,只有很少的修改 1.避开反斜杠$ 2.使用双引号 您的新代码现在看起来像这
private static final String TEXT = "this a test 1: $\\$$,test 2: $\\underline{\\rm defund}$, test 3:$$\\underline{\\rm defund}$$";
但是我在android中使用它,Java不支持
express模式
。谁能为我写一个Java模式
,或者给我一些提示?在Java中,只有很少的修改
1.避开反斜杠$
2.使用双引号
您的新代码现在看起来像这样
$\$$ or \$, $\underline{\rm defund}$ or \underline{\rm defund}
Pattern.compile((?=([^\\]?)(?:(?\\\$\$)\124\$)(.*?[^\\])(?:((?(bound2)\\\$\\\$\124\$));
注意:确保导入模式类看看我知道的两个技巧,我已经试过编译它了。java.util.regex.Pattern失败:线程“main”java.util.regex.PatternSyntaxException:索引64附近未关闭的字符类(?=([^])(?:(?:(?\$\$)|\$)(.*?[^])(?:((?(bound2)\$\$\\$)^在java.util.regex.Pattern.error(Pattern.java:1955)在java.util.regex.Pattern.clazz(Pattern.java:2548)I
$\$$ or \$, $\underline{\rm defund}$ or \underline{\rm defund}
Pattern.compile("(?=([^\\]?))(?:(?P<bound2>\\$\\$)|\\$)(.*?[^\\])(?:(?(bound2)\\$\\$|\\$))");