Java / Using String
How do I create a Regular expression pattern into non-greedy in Java?
The non-greedy regular expression constructs are similar to the greedy modifier with a question mark (?) immediately following the meta character.
For example, * (asterisk) meta character that matches zero or more is a greedy pattern while * (asterisk) followed with question mark *? matches same zero or more characters however it is non greedy.
See below are the examples of greedy construct and its equivalent non-greedy regular expression constructs in Java.
Construct | greedy | non-greedy |
zero or more | * | *? |
one or more | + | +? |
zero or one | ? | ?? |
More Related questions...