Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: The craziest RegExes you ever created

by Ovid (Cardinal)
on Jul 03, 2006 at 12:41 UTC ( #558982=note: print w/replies, xml ) Need Help??


in reply to The craziest RegExes you ever created

My craziest regex:

use re 'eval'; my $string = "abc"; my $length = length $string; my $regex = qr/(\G[$string]{0,$length}(?{print "# [$&][$'][$string]\n"}))/ x + 2; $string =~ $regex;

Bonus points if you can figure out why I wrote that. As a fun exercise, try to figure out what it does and how it does it.

Of course, this forking regular expression might top it. Since the regex engine is not re-entrant, if you need that power, you have to fork.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^2: The craziest RegExes you ever created
by demerphq (Chancellor) on Jul 03, 2006 at 13:08 UTC

    Since the regex engine is not re-entrant,

    Yet.

    My money is on dave_the_m getting it re-entrant before 5.10, which will just be one of many regex enhancements that will be in 5.10. (The short story is the engine will be a lot faster for many regexes.)

    ---
    $world=~s/war/peace/g

      demerphq wrote:

      My money is on dave_the_m getting [regular expressions] re-entrant before 5.10 ...

      Oh. My. God.

      I want. I want badly. Drool. (How did I not hear about this?)

      Hmm, who wants to bet that a Perl 6 alpha will be out first? :)

      Cheers,
      Ovid

      New address of my CGI Course.

        Hmm, who wants to bet that a Perl 6 alpha will be out first? :)

        Ill bet against that. :-) Although I'm not sure if its sporting, as I probably will be trying to help dave in his efforts... In fact I feel a little guilty I haven't already helped more.

        ---
        $world=~s/war/peace/g

      That would be the evilest ever, making 5.10 wait on that. I don't see why it hasn't just been pushed out the door already.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        5.10 isnt waiting on it. Its just that i think dave might have finished before 5.10's todo list is exhausted and we reach a feature freeze.

        Frankly i appreciate the extra time as i have more regex improvements to deliver and with the nice weather, world cup, and life, ive not had as much time or inclination lately to focus on hacking perl. I mean Frankfurt doesnt get the much nice weather and I dont want to miss what we do end up getting.

        ---
        $world=~s/war/peace/g

Re^2: The craziest RegExes you ever created
by Ieronim (Friar) on Jul 03, 2006 at 17:32 UTC
    I can only suppose that you were debugging some of your bigger regexes and made this regex to view how the regular expressions engine works. The regex you wrote prints out all steps of matching :)

    Am i right?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://558982]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2020-11-28 05:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?