Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

advanced regEx

by jithoosin (Scribe)
on Nov 02, 2005 at 13:18 UTC ( #504909=perlquestion: print w/replies, xml ) Need Help??

jithoosin has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: advanced regEx
by fishbot_v2 (Chaplain) on Nov 02, 2005 at 13:26 UTC

    This is a regex for unpacking URL-encoded strings. Your input string contains no encoded entities, and it passes through unchanged.

    URL encoded text entities are of the form %FF where FF is an arbitrary byte in hex. The represent the character with the ordinal value of that byte. The regex grabs these three character sequences and translates them back into the ASCII equivalent.

    update: see hex and pack for details of the hex-to-char translation.

      Hi fishbot.. thanks for the help...i am kiran from india & just started learning perl.....once again thanks for spending your precious time to help novices like me....
Re: advanced regEx
by polettix (Vicar) on Nov 02, 2005 at 13:37 UTC
    What the output is ?
    I'll skip this one - it takes nothing to put the text inside a text file, and execute it using the Perl interpreter. perlrun can help you with this, anyway.
    Explanation ?
    For regex in general, the main reference is perlre, but a look to perlretut is worth a look as well. In your case, perlop is also a good starting point, in particular the "Regexp Quote-Like Operators".

    In general, the "s/SOMETHING/OTHER/" construct makes substitutions. Wherever it finds "SOMETHING", it puts "OTHER". In this case, this substitution operator is applied to the $value variable, via the =~ binding operator. This can be found in perlop, of course.

    The "e" switch indicates that the "OTHER" (i.e. the 'pack("C", hex($1))' in your case) is to be considered an expression and not a pure sequence of characters, and the "g" switch indicates that the substitution has to be applied to every occurence of the text matched in the first "SOMETHING" part (i.e. the '%(..)' in your case). Globally, this seems born to replace every occurrence of "%XX" with the character whose hexadecimal representation is "XX".

    Could any one help me .......
    A whole lot is willing to help you here. But please take a look around, and in particular to the About the PerlMonks FAQ and How do I post a question effectively?. You forgot to use proper code tagging, and forced a janitor to do it for you. Welcome to the Monastery!

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
      hi frodo......thanks for the help....the explanation was simple awesome & amazing......especially the "e" switch.......i now find that the expression was "ADVANCED REGEX" only for me and not for you people...and i have to learn a lot...........................i am kiran from india...thanks for spending your precious time to help newbies like me.....
        I'm going to post this here instead of using private message because I hope other people see it.

        Please, in the future, take some time to actually properly format your messages. This makes it much easier for everyone else who uses the site to read it. For example, you don't capitalize the first letter of your sentences and you over use periods. Periods should be singular and used to denote the end of the sentence. Please do not put long strings of them between your sentences. I realize typing like that may be "easier" for you, but it's a really arrogant form of laziness, as it makes it much harder for everyone else who has to decipher it.
Re: advanced regEx
by Perl Mouse (Chaplain) on Nov 02, 2005 at 13:26 UTC
    Considering the regex looks for 3-character substrings starting with a %-sign, and $value doesn't contain any %-signs, the snippet will print "w/115/271/2337/14-11575/".
    Perl --((8:>*

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://504909]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2023-02-04 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (30 votes). Check out past polls.

    Notices?