Rule 1: The Regular Expression Engine Starts matching the input string as soon as possible. It searches for one character at a time until it finds a match.
For example:
String = 123 ABC 456 def
RegEx = [A-Z] *
Matching starts from ABC.
Rule 2: After a matching start is found, the Regular Expression Engine continues to match until a character is received in the mode.
For example:
String = 123 ABC 456 def
RegEx = [A-Z] *
The first match starts with ABC and ends when a space is not accepted by the mode.
Rule 3: The RegEx engine is greedy-as long as the mode permits, it will match as many characters as possible.
For example:
String = 'Dr Watson's watch'
RegEx = '.*'
Here we will match 'Dr Watson's Watch'. If the mode is changed '.*? ', Is "*" to become a non-Greedy qualifier. This will match 'Dr watson'
Rule 4: The RegEx engine is eager to implement matching, so it will backtrack the request to implement matching.
For example:
String = 'Hello world' s said K & R.
RegEx = '.*'
Match 'Hello world' here '.
If you set the mode to a non-backtracing "'(?>. *) '"Then no matching is found. Because ". *" matches all characters on the right until the end, and does not use backtracing, it cannot be matched.
Rule 5: The RegEx engine always selects the first option.
For example:
String = 1234 123 3456
RegEx = (\ D {2} | \ D {3} | \ D {4 })
The matching result is as follows:
12
34
12
34
56