Surprising regular expression !
-
Hi, All,
Here is a little exercise for a Sunday !
-
Start N++ and open a new file (
Ctrl + N) -
Write
2,047consecutive empty lines -
Save your file
-
Move back to its very beginning ( Ctrl + Home )
-
Select the
Edit > Column Editor..option or use theAlt + Cshortcut -
Enter the values
0 , 1 , 1to define the sequence -
Select the leading
Zerosoption and theBinformat
=> You should get a list of binary numbers between
0and111 1111 1111-
Now, open the Mark dialog (
Ctrl + M)-
Uncheck all box options
-
Enter the regex
^(0|(1(01*0)*1))*$in the Find what field -
Check the
Bookmark lineandWrap aroundoptions -
Select the
Regular expressionmode -
Click on the
Mark Allbutton
-
-
Close the Mark dialog or hit the
ESCkey
Now, in your opinion, what do all these marked lines represent ? …
After a while, it should be enough easy to detect that any marked line is a number
multiple of 3!Therefore, the main takeaway from this text, is that regexes can simulate mathematical formulas !
Of course, I did not come up with that regex on my own, but by referring to the last example in this Wikipedia article :
https://en.wikipedia.org/wiki/Regular_expression#Formal_definition
Now, I suppose that other regexes could simulate other multiples or formulas, as long, as we simply use the binary format but I have not tested anything yet !
Best Regards,
guy038
-
-
G guy038 referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login