images to svg
This commit is contained in:
parent
a31e881856
commit
3ba28aa104
734 changed files with 11682 additions and 245 deletions
|
@ -46,19 +46,19 @@ These common words do not make it obvious why the regexp fails, so let's elabora
|
|||
|
||||
Then it advances: goes to the next positions in the source string and tries to find the first character of the pattern there, and finally finds the quote at the 3rd position:
|
||||
|
||||

|
||||

|
||||
|
||||
2. The quote is detected, and then the engine tries to find a match for the rest of the pattern. It tries to see if the rest of the subject string conforms to `pattern:.+"`.
|
||||
|
||||
In our case the next pattern character is `pattern:.` (a dot). It denotes "any character except a newline", so the next string letter `match:'w'` fits:
|
||||
|
||||

|
||||

|
||||
|
||||
3. Then the dot repeats because of the quantifier `pattern:.+`. The regular expression engine builds the match by taking characters one by one while it is possible.
|
||||
|
||||
...When does it become impossible? All characters match the dot, so it only stops when it reaches the end of the string:
|
||||
|
||||

|
||||

|
||||
|
||||
4. Now the engine finished repeating for `pattern:.+` and tries to find the next character of the pattern. It's the quote `pattern:"`. But there's a problem: the string has finished, there are no more characters!
|
||||
|
||||
|
@ -66,7 +66,7 @@ These common words do not make it obvious why the regexp fails, so let's elabora
|
|||
|
||||
In other words, it shortens the match for the quantifier by one character:
|
||||
|
||||

|
||||

|
||||
|
||||
Now it assumes that `pattern:.+` ends one character before the end and tries to match the rest of the pattern from that position.
|
||||
|
||||
|
@ -74,13 +74,13 @@ These common words do not make it obvious why the regexp fails, so let's elabora
|
|||
|
||||
5. ...So the engine decreases the number of repetitions of `pattern:.+` by one more character:
|
||||
|
||||

|
||||

|
||||
|
||||
The quote `pattern:'"'` does not match `subject:'n'`.
|
||||
|
||||
6. The engine keep backtracking: it decreases the count of repetition for `pattern:'.'` until the rest of the pattern (in our case `pattern:'"'`) matches:
|
||||
|
||||

|
||||

|
||||
|
||||
7. The match is complete.
|
||||
|
||||
|
@ -116,29 +116,29 @@ To clearly understand the change, let's trace the search step by step.
|
|||
|
||||
1. The first step is the same: it finds the pattern start `pattern:'"'` at the 3rd position:
|
||||
|
||||

|
||||

|
||||
|
||||
2. The next step is also similar: the engine finds a match for the dot `pattern:'.'`:
|
||||
|
||||

|
||||

|
||||
|
||||
3. And now the search goes differently. Because we have a lazy mode for `pattern:+?`, the engine doesn't try to match a dot one more time, but stops and tries to match the rest of the pattern `pattern:'"'` right now:
|
||||
|
||||

|
||||

|
||||
|
||||
If there were a quote there, then the search would end, but there's `'i'`, so there's no match.
|
||||
4. Then the regular expression engine increases the number of repetitions for the dot and tries one more time:
|
||||
|
||||

|
||||

|
||||
|
||||
Failure again. Then the number of repetitions is increased again and again...
|
||||
5. ...Till the match for the rest of the pattern is found:
|
||||
|
||||

|
||||

|
||||
|
||||
6. The next search starts from the end of the current match and yield one more result:
|
||||
|
||||

|
||||

|
||||
|
||||
In this example we saw how the lazy mode works for `pattern:+?`. Quantifiers `pattern:+?` and `pattern:??` work the similar way -- the regexp engine increases the number of repetitions only if the rest of the pattern can't match on the given position.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue