Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl = reg Exp - Cut info in middle

by dani_cv_74 (Novice)
on Mar 23, 2006 at 16:14 UTC ( [id://538779]=perlquestion: print w/replies, xml ) Need Help??

dani_cv_74 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: Perl = reg Exp - Cut info in middle
by Tanktalus (Canon) on Mar 23, 2006 at 16:26 UTC

    First help: How (Not) To Ask A Question

    Second - what have you tried?

    Third, this is an X-Y question: "How do I do X with Y?" Why don't you want to do X with X? You want to split on colons, and get the second field, that sounds exactly like:

    my $second_field = (split /:/, $string)[1]
    Or maybe I'm just not reading the problem right - there's not a lot of info to go on here.

Re: Perl = reg Exp - Cut info in middle
by davidrw (Prior) on Mar 23, 2006 at 16:23 UTC
    look at perlop and perlre for the s/// substitution .. something like:
    $s =~ s/Info_to_cut//;
    Though using the split function might work better ... depends on your exact needs -- can you provide some real samples (input and desired output)?
Re: Perl = reg Exp - Cut info in middle
by timos (Beadle) on Mar 23, 2006 at 16:28 UTC
    Of course this could be done by regex:
    my $yourstring="someinfo:Info_to_cut:Take_me_off"; $yourstring=~/^.*?:(.*?):.*$/; $info=$1;
    I assumed that there are only two ':' in your string and you wanted the part between them.
      I think $yourstring=~/^[^:]*:([^:]*)/; might be faster, but only a Benchmark will tell for sure.
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl = reg Exp - Cut info in middle
by Melly (Chaplain) on Mar 23, 2006 at 16:26 UTC

    You might need to give a larger sample of your data, but if all you are doing is trying to grab the chars between the colons, then:

    $_ = 'hello_world:foo_bar:goodbye_world'; /\w+:(\w+):\w+/; print $1;
    Tom Melly, tom@tomandlu.co.uk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-29 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found