Java regex Lookaround
2013-10-22 01:39
387 查看
see: http://www.rexegg.com/regex-lookarounds.html
Four ways of using lookarounds:
(?= lookahead
(?! negative lookahead
(?<= lookbehind
(?<! negative lookbehind
Lookaround after match:
n
n
n
n
Four ways of using lookarounds:
(?= lookahead
(?=\d{3} dollars).{3}(Lookahead). Looks ahead for three digits followed by " dollars". Matches "100" in "100 dollars"
(?! negative lookahead
(?!=\d{3} pesos)\d{3}(Negative Lookahead). Makes sure what follows is not three digits followed by " pesos". Matches "100" in "100 dollars"
(?<= lookbehind
(?<=USD)\d{3}(Lookbehind). Makes sure "USD" precedes the text to be matched. Matches "100" in "USD100"
(?<! negative lookbehind
(?<!USD)\d{3}(Negative Lookbehind). Makes sure "USD" does not precede the text to be matched. Matches "100" in "JPY100"
Lookaround after match:
\d{3}(?= dollars)(Lookahead). Makes sure " dollars" follows the three digits to be matched. Matches "100" in "100 dollars"
\d{3}(?! dollars)(Negative Lookahead) Makes sure " dollars" does not follow the three digits to be matched. Matches "100" in "100 pesos"
.{3}(?<=USD\d{3})(Lookbehind). Looks behind for "USD" followed by three digits. Matches "100" in "USD100"
\d{3}(?<!USD\d{3})(Negative Lookbehind). Makes sure what precedes is not "USD" followed by three digits. Matches "100" in "JPY100"
n
n
n
n
相关文章推荐
- import java.util.regex.Pattern的问题
- JAVA 正则表达式 Regex
- What does a Java array look like in memory?(未看)
- 关于java.util.regex.PatternSyntaxException Dangling meta character '*' near index 0解决办法
- LookupTable (Java 2 Platform SE 5.0)
- java regex
- Dalvik: how Google routed around Sun’s IP-based licensing restrictions on Java ME
- java.util.regex.PatternSyntaxException 错误问题
- Java regular expression regex
- Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 0 [ ^
- Java中的LookAndFeel
- java.util.regex.Pattern
- Java Regex中Matcher类的group(int m)方法
- java.util.regex
- Java常用正则表达式验证工具类RegexUtils.java
- java.util.regex 正则表达式
- JAVA学习59_ java.util.regex.PatternSyntaxException: Unexpected internal error near index 1 \
- java.util.regex.PatternSyntaxException: Unclosed counted closure near index 14
- java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1:
- Java正则表达式,java.util.regex