Regular Expression test

English main discussion
Post Reply
  • Author
  • Message
Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Regular Expression test

Post by Instructor »

Test version of AkelPad.

Now all quantifiers are greedy (except for single dot, like, ".*" or ".{5,10}"). To make it non-greedy (old behaviour) use "?" after quantifier, like, "\d*?".

Offline
Posts: 582
Joined: Mon Apr 08, 2013 9:50 pm
Location: Win7SP1x64, APx64

Post by Drugmix »

Hooray! Finally the greediness is controllable!

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Text for test:
"abcabbbb"

RegExp:
"ab??b" - works
"ab*?b" - works
"ab+?b" - works
"ab{2,3}?b" - works

"ab?b" - works incorrectly, left "ab" not matches
"ab*b" - doesn't work
"ab+b" - doesn't work
"ab{2,3}b" - works

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

Test version

Now single dot, like, ".*" or ".{5,10}" is also greedy. AkelPad regular expressions greediness works is in the following way:
- Pattern "a.*b" in "aabbccaabbcc" matches "aabb" (not "aabbccaabb")
- Pattern "a.*?b" in "aabbccaabbcc" matches "aab"

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

Test version

Returned back to the first variant (single dot, like, ".*" or ".{5,10}" is non-greedy). Second acquired unneeded slowdown.

AkelPad regular expressions greediness works consequentially:
- Pattern "ab?b" in "abc" has no matches, because "ab?" matches "ab" and next "b" has no match. Correct pattern will be "abb?".

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Instructor wrote:single dot, like, ".*" or ".{5,10}" is non-greedy
And these:
[\d\D]*
[\s\S]*
[\w\W]*
are greedy?

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

KDJ
Yes, but they are useless constructions, because AkelPad regular expressions greediness works consequentially.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

In test version, backward search (Shift+F3) does not work properly.
What: \w+
Text:

Code: Select all

a, bc, def


Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »


KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Instructor
Now it works properly, thanks.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Instructor
AkelPad ver. 4.9.7 dev (dated 2015-10-20), "Find" dialog.
Option ". matches \n" is working inversely, as ". not matches \n".

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

KDJ
Corrected, thanks.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Instructor
AkelPad ver. 4.9.8 dev (2016-05-17), "Find" dialog.
What:

Code: Select all

(?s)^.+?$
Direction: "Down" or "Up".
If caret is at end of document, AkelPad crashes.

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »


KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Instructor
Now it works well, thank you very much.
Post Reply