11. The DFA Engine - An Example
- Consider this regex:
to(morrow|mmorrow|mmy)
Searching this string with tomorrow mis-spelled:
I hope this makes sense tommorrow.
- Let's work through the example - I've used the "^" character to represent the
position in the target string currently being looked at, and the "*"
characters are the characters in the string that are part of the current match.
The "^" character is also used to represent the place or places in the regex
string that the DFA engine has marked as places in the regex that the string
is currently matching.
- We'll start looking with the regex engine looking at the beginning of the line
(i.e. at the non-character position there):
Position in string | Match in regex
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ |
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ |
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ |
------------------------------------------------------------
etc.
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ | ^
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ |
------------------------------------------------------------
etc.
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
^ | ^
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
*^ | ^
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
**^ | ^ ^ ^
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
***^ | ^ ^
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
****^ | ^
------------------------------------------------------------
etc.
------------------------------------------------------------
I hope this makes sense tommorrow. | to(morrow|mmorrow|mmy)
********^ | ^
------------------------------------------------------------
- So, at the end, it's matched the mis-spelled word "tommorrow".
|