Community
    • Login

    Surprising regular expression !

    Scheduled Pinned Locked Moved Blogs
    1 Posts 1 Posters 19 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
      guy038
      last edited by

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