Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 428 Bytes

regex-java.md

File metadata and controls

22 lines (15 loc) · 428 Bytes

Greedy and non-greedy

By defaut, regex are greedy in Java. Adding a ? makes the regex non greedy.

A.*c   # greedy     : AbcAbc is matched in AbcAbc
A.*?c  # non greedy : Abc is matched in AbcAbc 

Negative look-ahead

Important : negative look-ahead does not consume characters !

q(?!u) # match q in "Iraq", but does not match q in "quit"

Non-capturing group

(?:X) # X is the pattern