Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: (wil) Re: regex: extract a substring

by krujos (Curate)
on May 23, 2002 at 21:28 UTC ( #168901=note: print w/replies, xml ) Need Help??

in reply to (wil) Re: regex: extract a substring
in thread regex: extract a substring

Do keep in mind that wil's example will make foo equal to the characters between abc and xyz. i.e. $foo == "hello" if you are trying to extract to another variable you need to do something more like this.
$foo = "abchelloxyz"; $foo =~ /abc([\w]+)xyz/; $bar = $1;

the value of $foo is unchanged. ---Mogaka is good

Replies are listed 'Best First'.
Re3: regex: extract a substring
by Hofmator (Curate) on May 24, 2002 at 17:07 UTC
    $foo =~ /abc([\w]+)xyz/; $bar = $1;

    or in one line:

    ($bar) = /abc([\w]+)xyz/;

    From perlop:

    If the /g option is not used, m// in a list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 etc. are also set, and that this differs from Perl 4's behavior.) When there are no parentheses in the pattern, the return value is the list (1) for success. With or without parentheses, an empty list is returned upon failure.

    -- Hofmator

Re: Re: (wil) Re: regex: extract a substring
by insensate (Hermit) on May 23, 2002 at 23:12 UTC
    en passant:
    $foo='abchelloxyz'; ($bar=$foo)=~s/abc(\w+)xyz/\1/;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://168901]
[1nickt]: hm, what did I do wrong? No download link in a code secrtion of a node I just posted ...
[Corion]: I see a download link there?
[Corion]: (at least the curl stuff is in a download link)
[Corion]: Also, I think the OPs problem is on their intranet and not on the internet (also, they should likely use WWW::Mechanize instead, which knows about cookie)
[1nickt]: yes, could be.
[1nickt]: I don;t see the link , definitely, after reloading the node
[1nickt]: Is it possible to disable it?
[Discipulus]: if you mean [download] after the code it is there 1nickt

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-05-23 18:14 GMT
Find Nodes?
    Voting Booth?