« first day (1286 days earlier)      last day (2506 days later) » 

4:14 AM
@bwoebi Why is 100_00011 a non-match?
100_00011 --> 1([C]00_0001)1 --> 1([C]0([C]0_000)1)1 --> 1([C]0([C]0([C]_00)0)1)1
This seems to work, but I'm not entirely sure
(?(DEFINE)
(?<b> _[01]*1(?=\k<e>$) | (?=.*(?<e>[01]\k<e>)$)[01](?&b)[01] )
(?<c> _[01]*0(?=\k<e>$) | (?=.*(?<e>[01]\k<e>)$)[01](?&c)[01] )
)
^(0(?=.*(?<e>1)$)(?&b)1 | 1(?=.*(?<e>0)$)(?&b)0 | 1(?=.*(?<e>1)$)(?&c)1 | 0(?=.*(?<e>0)$)(?&c)0)$
Flags: gmxJ
The idea is to make sure _[01]*1 not overconsuming stuffs
By using group e to control the suffix string
The thing is, I don't quite understand how capturing group works in conjunction with recursion
If I place the S inside DEFINE, the code doesn't work
But it works when I expand it out as shown above
@HamZa I don't even visit the tag anymore. I feel like I learn more from code golf site than here
 
 
6 hours later…
10:05 AM
@bwoebi: I wrote a Python script to confirm that the regex actually works.
Well, at least for all the string of the form [01]*_[01]*, up to length 18
I guess that is sufficient test, since errors if any would happen at length 6-7, when the recursion goes deeper than 1 level
 
10:21 AM
The idea is: as routine calls in PCRE are atomic, we need to perform checks before calling the routine call
Or eliminate routine calls where you require backtracking
(?J)(?(DEFINE)
(?<b> _[01]*1(?=\k<e>$) | (?=.*(?<e>[01]\k<e>)$)[01](?&b)[01] )
(?<c> _[01]*0(?=\k<e>$) | (?=.*(?<e>[01]\k<e>)$)[01](?&c)[01] )
(?<s>0(?=.*(?<e>1)$)(?&b)1 | 1(?=.*(?<e>0)$)(?&b)0 | 1(?=.*(?<e>1)$)(?&c)1 | 0(?=.*(?<e>0)$)(?&c)0)
)
^(?&s)$
Ah, this one works. The one that I tried and didn't work has s group at the beginning
There is a bug in J mode, where the engine selects the content of repeated named group by the one which is defined first in the regex, iirc
 
 
1 hour later…
11:54 AM
@nhahtdh (That was a mistake)
 
12:09 PM
Hmm
@nhahtdh Ah… I see how it works (also thanks for the J flag, didn't know about it yet)
 
@nhahtdh Thus the backreference trick worked once again… I'll have to try whether I can expand this to 100_00001_000110, i.e. the third digit from right instead of the last one…
 
1:04 PM
@nhahtdh regex101.com/r/vD1lM7/2 … yep, wasn't hard to expand :-) thanks a lot…
@nhahtdh do you want a bounty or such? … but sounded like you do not really care about SO anymore?
 
 
1 hour later…
 
3 hours later…
 
2 hours later…
 
2 hours later…
9:48 PM
@nhahtdh … thanks for your help … regex101.com/r/yD1kL7/12 :-)
This one little trick from yours was really all I was missing :-)
I'll probably write it up on SO or such … but not right now.
 
 
2 hours later…
11:51 PM
 

« first day (1286 days earlier)      last day (2506 days later) »