Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

reg-exp problem

by perlplayer (Sexton)
on Sep 09, 2008 at 10:53 UTC ( #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

      thanks to all, i will go through the documentation

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2022-10-01 14:35 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.