我正在使用下一个来源:
Matcher mather = Pattern.compile("(\\p{Alnum}*" + subtext + "\\p{Alnum}*)").matcher(ssb.toString());
但是如果字符串 = "fefrefewre-rfrefrf"
或 "fefrefewre`rfrefrf"我的妈妈 = "fefrefewre"
我需要 mather = "fefrefewre-rfrefrf"
或 "fefrefewre`rfrefrf"
如何在字符串正则表达式中添加字符“-”和“`”?
subtext = “fefref”
- 例如
最佳答案
看起来除了“\p{alpha}”之外,您只想匹配“-”和“`”符号。
我认为这是最直接的解决方案:
Matcher mather = Pattern.compile("((\\p{Alnum}|[\\-`])*" + subtext + "(\\p{Alnum}|[\\-`])*)").matcher(ssb.toString());
关于java - 如何将字符 "-"和 "` "添加到字符串正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15188818/