Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

reg-exp problem

by perlplayer (Sexton)
on Sep 09, 2008 at 10:53 UTC ( [id://710029]=perlquestion: print w/replies, xml ) Need Help??

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

can any one please answer that what the regular expression inside this split statement will match
split /[{},*]/, $_
this is part of a code so don't bother about $_

Replies are listed 'Best First'.
Re: reg-exp problem
by Corion (Patriarch) on Sep 09, 2008 at 10:55 UTC

    Have you considered trying the code and looking at how it splits the input?

    In perlre, you find the documentation of how regular expressions are constructed.

      ... and if you don't understand perlre (it's more reference documentation than introduction) read perlretut instead.

      Or you could use the module YAPE::Regex::Explain, which gives you a human readable description of what it matches.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: reg-exp problem
by ady (Deacon) on Sep 09, 2008 at 11:21 UTC
    #!/usr/bin/perl -w use strict; use Data::Dumper; $_ = "{Just} another, Perl*hacker."; my @rray = split /[{},*]/, $_; print Dumper( \@rray);
    ------------------------------------
    $VAR1 = [ '', 'Just', ' another', ' Perl', 'hacker.' ];
    Allan Dystrup
Re: reg-exp problem
by RMGir (Prior) on Sep 09, 2008 at 11:34 UTC
    As others have pointed out, perlre or perlretut are recommended reading, because this is a very important and basic construct in regular expressions.

    In a regex, [] surround a "character class", meaning that it matches any of the characters inside the square brackets.

    Since split divides a string based on its delimiter regex, in this case, your input string is being split on any of the { } , * characters.

    $ $ perl -e'print "$_\n" foreach split /[,{}*]/,"this{is*a}test,of"' this is a test of

    Mike
      thanks to all, i will go through the documentation

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-29 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found