images to svg
|
@ -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.
|
||||
|
||||
|
|
Before Width: | Height: | Size: 7.9 KiB |
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="463px" height="130px" viewBox="0 0 463 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>witch_greedy1.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="regexp" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="witch_greedy1.svg">
|
||||
<text id="a-"witch"-and-her-"b" font-family="PTMono-Regular, PT Mono" font-size="22" font-weight="normal" fill="#8A704D">
|
||||
<tspan x="20" y="112">a "witch" and her "broom" is one</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1" stroke="#E8C48E" x="45.5" y="50.5" width="14" height="76"></rect>
|
||||
<path d="M52.0039062,60.4414062 L51.6757812,65.9375 L49.7539062,65.9375 L49.4140625,60.4414062 L52.0039062,60.4414062 Z M56.5625,60.4414062 L56.234375,65.9375 L54.3125,65.9375 L53.9726562,60.4414062 L56.5625,60.4414062 Z" id="--"-----------------" fill="#CB1E31"></path>
|
||||
<path id="Line" d="M51.5,30.5 L51.5,8.5 L53.5,8.5 L53.5,30.5 L59.5,30.5 L52.5,44.5 L45.5,30.5 L51.5,30.5 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 7.7 KiB |
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="463px" height="130px" viewBox="0 0 463 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>witch_greedy2.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="regexp" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="witch_greedy2.svg">
|
||||
<text id="a-"witch"-and-her-"b" font-family="PTMono-Regular, PT Mono" font-size="22" font-weight="normal" fill="#8A704D">
|
||||
<tspan x="20" y="107">a "witch" and her "broom" is one</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1" stroke="#E8C48E" x="45.5" y="45.5" width="28" height="76"></rect>
|
||||
<path d="M52.0039062,55.4414062 L51.6757812,60.9375 L49.7539062,60.9375 L49.4140625,55.4414062 L52.0039062,55.4414062 Z M56.5625,55.4414062 L56.234375,60.9375 L54.3125,60.9375 L53.9726562,55.4414062 L56.5625,55.4414062 Z M66.0898438,68.3085938 C66.3554701,68.3085938 66.6074207,68.3593745 66.8457031,68.4609375 C67.0839856,68.5625005 67.2910147,68.7031241 67.4667969,68.8828125 C67.642579,69.0625009 67.7812495,69.2714832 67.8828125,69.5097656 C67.9843755,69.7480481 68.0351562,70.0039049 68.0351562,70.2773438 C68.0351562,70.5429701 67.9843755,70.7929676 67.8828125,71.0273438 C67.7812495,71.2617199 67.642579,71.466796 67.4667969,71.6425781 C67.2910147,71.8183603 67.0839856,71.9570307 66.8457031,72.0585938 C66.6074207,72.1601568 66.3554701,72.2109375 66.0898438,72.2109375 C65.8164049,72.2109375 65.5625012,72.1601568 65.328125,72.0585938 C65.0937488,71.9570307 64.8886728,71.8183603 64.7128906,71.6425781 C64.5371085,71.466796 64.398438,71.2617199 64.296875,71.0273438 C64.195312,70.7929676 64.1445312,70.5429701 64.1445312,70.2773438 C64.1445312,70.0039049 64.195312,69.7480481 64.296875,69.5097656 C64.398438,69.2714832 64.5371085,69.0625009 64.7128906,68.8828125 C64.8886728,68.7031241 65.0937488,68.5625005 65.328125,68.4609375 C65.5625012,68.3593745 65.8164049,68.3085938 66.0898438,68.3085938 L66.0898438,68.3085938 Z" id="--".----------------" fill="#CB1E31"></path>
|
||||
<path id="Line" d="M55.5,33.5 L47.5,33.5 L47.5,31.5 L55.5,31.5 L55.5,25.5 L69.5,32.5 L55.5,39.5 L55.5,33.5 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 9.8 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 7.7 KiB |
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="463px" height="130px" viewBox="0 0 463 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>witch_lazy3.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="regexp" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="witch_lazy3.svg">
|
||||
<text id="a-"witch"-and-her-"b" font-family="PTMono-Regular, PT Mono" font-size="22" font-weight="normal" fill="#8A704D">
|
||||
<tspan x="20" y="105">a "witch" and her "broom" is one</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1" stroke="#E8C48E" x="45.5" y="43.5" width="28" height="76"></rect>
|
||||
<path d="M52.0039062,53.4414062 L51.6757812,58.9375 L49.7539062,58.9375 L49.4140625,53.4414062 L52.0039062,53.4414062 Z M56.5625,53.4414062 L56.234375,58.9375 L54.3125,58.9375 L53.9726562,53.4414062 L56.5625,53.4414062 Z M66.0898438,66.3085938 C66.3554701,66.3085938 66.6074207,66.3593745 66.8457031,66.4609375 C67.0839856,66.5625005 67.2910147,66.7031241 67.4667969,66.8828125 C67.642579,67.0625009 67.7812495,67.2714832 67.8828125,67.5097656 C67.9843755,67.7480481 68.0351562,68.0039049 68.0351562,68.2773438 C68.0351562,68.5429701 67.9843755,68.7929676 67.8828125,69.0273438 C67.7812495,69.2617199 67.642579,69.466796 67.4667969,69.6425781 C67.2910147,69.8183603 67.0839856,69.9570307 66.8457031,70.0585938 C66.6074207,70.1601568 66.3554701,70.2109375 66.0898438,70.2109375 C65.8164049,70.2109375 65.5625012,70.1601568 65.328125,70.0585938 C65.0937488,69.9570307 64.8886728,69.8183603 64.7128906,69.6425781 C64.5371085,69.466796 64.398438,69.2617199 64.296875,69.0273438 C64.195312,68.7929676 64.1445312,68.5429701 64.1445312,68.2773438 C64.1445312,68.0039049 64.195312,67.7480481 64.296875,67.5097656 C64.398438,67.2714832 64.5371085,67.0625009 64.7128906,66.8828125 C64.8886728,66.7031241 65.0937488,66.5625005 65.328125,66.4609375 C65.5625012,66.3593745 65.8164049,66.3085938 66.0898438,66.3085938 L66.0898438,66.3085938 Z" id="--"."---------------" fill="#CB1E31"></path>
|
||||
<polygon id="Path" fill="#5C8058" points="78.3945312 53.4414062 78.0664062 58.9375 76.1445312 58.9375 75.8046875 53.4414062"></polygon>
|
||||
<polygon id="Path" fill="#5C8058" points="82.953125 53.4414062 82.625 58.9375 80.703125 58.9375 80.3632812 53.4414062"></polygon>
|
||||
<path id="Line" d="M60,34.5 L45,34.5 L45,32.5 L60,32.5 L60,26.5 L74,33.5 L60,40.5 L60,34.5 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 7.9 KiB |
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="463px" height="130px" viewBox="0 0 463 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 55.2 (78181) - https://sketchapp.com -->
|
||||
<title>witch_lazy4.svg</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="regexp" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="witch_lazy4.svg">
|
||||
<text id="a-"witch"-and-her-"b" font-family="PTMono-Regular, PT Mono" font-size="22" font-weight="normal" fill="#8A704D">
|
||||
<tspan x="20" y="105">a "witch" and her "broom" is one</tspan>
|
||||
</text>
|
||||
<rect id="Rectangle-1" stroke="#E8C48E" x="45.5" y="43.5" width="40" height="76"></rect>
|
||||
<path d="M52.0039062,53.4414062 L51.6757812,58.9375 L49.7539062,58.9375 L49.4140625,53.4414062 L52.0039062,53.4414062 Z M56.5625,53.4414062 L56.234375,58.9375 L54.3125,58.9375 L53.9726562,53.4414062 L56.5625,53.4414062 Z M66.0898438,66.3085938 C66.3554701,66.3085938 66.6074207,66.3593745 66.8457031,66.4609375 C67.0839856,66.5625005 67.2910147,66.7031241 67.4667969,66.8828125 C67.642579,67.0625009 67.7812495,67.2714832 67.8828125,67.5097656 C67.9843755,67.7480481 68.0351562,68.0039049 68.0351562,68.2773438 C68.0351562,68.5429701 67.9843755,68.7929676 67.8828125,69.0273438 C67.7812495,69.2617199 67.642579,69.466796 67.4667969,69.6425781 C67.2910147,69.8183603 67.0839856,69.9570307 66.8457031,70.0585938 C66.6074207,70.1601568 66.3554701,70.2109375 66.0898438,70.2109375 C65.8164049,70.2109375 65.5625012,70.1601568 65.328125,70.0585938 C65.0937488,69.9570307 64.8886728,69.8183603 64.7128906,69.6425781 C64.5371085,69.466796 64.398438,69.2617199 64.296875,69.0273438 C64.195312,68.7929676 64.1445312,68.5429701 64.1445312,68.2773438 C64.1445312,68.0039049 64.195312,67.7480481 64.296875,67.5097656 C64.398438,67.2714832 64.5371085,67.0625009 64.7128906,66.8828125 C64.8886728,66.7031241 65.0937488,66.5625005 65.328125,66.4609375 C65.5625012,66.3593745 65.8164049,66.3085938 66.0898438,66.3085938 L66.0898438,66.3085938 Z M79.2851562,66.3085938 C79.5507826,66.3085938 79.8027332,66.3593745 80.0410156,66.4609375 C80.2792981,66.5625005 80.4863272,66.7031241 80.6621094,66.8828125 C80.8378915,67.0625009 80.976562,67.2714832 81.078125,67.5097656 C81.179688,67.7480481 81.2304688,68.0039049 81.2304688,68.2773438 C81.2304688,68.5429701 81.179688,68.7929676 81.078125,69.0273438 C80.976562,69.2617199 80.8378915,69.466796 80.6621094,69.6425781 C80.4863272,69.8183603 80.2792981,69.9570307 80.0410156,70.0585938 C79.8027332,70.1601568 79.5507826,70.2109375 79.2851562,70.2109375 C79.0117174,70.2109375 78.7578137,70.1601568 78.5234375,70.0585938 C78.2890613,69.9570307 78.0839853,69.8183603 77.9082031,69.6425781 C77.732421,69.466796 77.5937505,69.2617199 77.4921875,69.0273438 C77.3906245,68.7929676 77.3398438,68.5429701 77.3398438,68.2773438 C77.3398438,68.0039049 77.3906245,67.7480481 77.4921875,67.5097656 C77.5937505,67.2714832 77.732421,67.0625009 77.9082031,66.8828125 C78.0839853,66.7031241 78.2890613,66.5625005 78.5234375,66.4609375 C78.7578137,66.3593745 79.0117174,66.3085938 79.2851562,66.3085938 L79.2851562,66.3085938 Z" id="--".."--------------" fill="#CB1E31"></path>
|
||||
<polygon id="Path" fill="#5C8058" points="91.5898438 53.4414062 91.2617188 58.9375 89.3398438 58.9375 89 53.4414062"></polygon>
|
||||
<polygon id="Path" fill="#5C8058" points="96.1484375 53.4414062 95.8203125 58.9375 93.8984375 58.9375 93.5585938 53.4414062"></polygon>
|
||||
<path id="Line" d="M70,30.5 L46,30.5 L46,28.5 L70,28.5 L70,22.5 L84,29.5 L70,36.5 L70,30.5 Z" fill="#EE6B47" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 17 KiB |