是否有更容易的方法来检测破折号是否意味着减去/负/或只是一个破折号,而不是对每个模式执行单独的regex模式搜索?
(E)
4-word = dash
word-4 = dash
word-word = dash
4-4 = minus
-4 = negative
是否有可能将其合并为一个正则搜索?还是我必须用不同的搜索来寻找每一个?
发布于 2015-02-12 21:56:33
您可以使用这个基于查找器的正则表达式:
-(?=\D)|(?<=\D)(?<!^)-
- # Match a literal
(?=\D) # Lookahead that means match a literal - if not followed by a non-digit
| # regex alternation (OR)
(?<=\D) # Lookbehind that means if not preceded by a non-digit
(?!^) # Negative Lookahead that means not preceded by line start
- # Match a literal -
https://stackoverflow.com/questions/28488509
复制相似问题