Community
    • Login

    Surprising regular expression !

    Scheduled Pinned Locked Moved Blogs
    1 Posts 1 Posters 371 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guy038G Offline
      guy038
      last edited by guy038

      Hi, All,

      Here is a little exercise for a Sunday !


      • Start N++ and open a new file ( Ctrl + N )

      • Write 2,047 consecutive empty lines

      • Save your file

      • Move back to its very beginning ( Ctrl + Home )

      • Select the Edit > Column Editor.. option or use the Alt + C shortcut

      • Enter the values 0 , 1 , 1 to define the sequence

      • Select the leading Zeros option and the Bin format

      => You should get a list of binary numbers between 0 and 111 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 line and Wrap around options

        • Select the Regular expression mode

        • Click on the Mark All button

      • Close the Mark dialog or hit the ESC key


      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

      1 Reply Last reply Reply Quote 1
      • guy038G 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
      • First post
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors