in reply to Re: string selection from a character class
in thread string selection from a character class

#!/usr/bin/env perl use warnings; use strict; while (<DATA>) { print $2 . "\n" if /(\d)\st=(\w+)/; } __DATA__ 0 1 t=something 2 t=3foo7bar
Creates the following output:
something 3foo7bar
Is this what you are trying to achieve? In any case, you should heed Limbic~Region's advice on understanding character classes (what goes into square brackets in a regex.)

Replies are listed 'Best First'.
Re^3: string selection from a character class
by karden (Novice) on Jul 12, 2007 at 16:16 UTC
    Thx toolic

    Your solution is exactly the solution I also am using to overcome and it works enough for me.

    Before my very first posting I was doing (in a loop):

    $word =~ /^(\d)\st=(\S+)/; next if ($1 == 0); print "$2\n";
    But in this way, for $word="0", pattern was not matched so previous loop's $1 and $2 was printed. And program functioned incorrectly.

    Anyway, now I am doing:

    next if(!($word =~ /(\d)\st=(\S+)/)); print "$2\n";
    and it works ok for my task.

    I thank you for your replies.