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

hi all,
i have a data sm thg like this
28504    0    abc    148782859    42    101M i want to get only the field which is just aftr abc i,e., 148782859
when i am using ^[1-9] it is printing other numbers as well i want only 148782859 which is after abc

Replies are listed 'Best First'.
Re: regular expressions on the basis of suffix
by choroba (Cardinal) on Jul 23, 2012 at 11:03 UTC
    If you want the field which is just after abc, do not look for numbers:
    my ($after_abc) = $string =~ /abc\t([0-9]+)/;
Re: regular expressions on the basis of suffix
by i5513 (Pilgrim) on Jul 23, 2012 at 12:31 UTC

    If your data is homogeneous, you can use split, if you want, as alternative to regex (use undef to discard the values that are not interesting for you):

    my (undef,undef,undef,$val,undef,undef)=split /\s/,"28504 0 abc 148782859 42 101M";

    $val have the value that you need in this example

      Or just the number you need:

      my $var = (split /\s/,"28504 0 abc 148782859 42 101M")[3]
Re: regular expressions on the basis of suffix
by mjscott2702 (Pilgrim) on Jul 23, 2012 at 14:13 UTC
    Assuming the abc could be any non-numeric string, something like /\D+\s+(\d+)/ should get what you want