FAQ
hi,

i have following string.

$val = "11.0.56.10000";

i need to write regular expression which should match only "56" and print

please suggest

regards
irfan

Search Discussions

  • Shlomi Fish at Sep 10, 2011 at 5:47 pm
    Hi Irfan,

    On Sat, 10 Sep 2011 10:23:31 -0700 (PDT)
    Irfan Sayed wrote:
    hi,

    i have following string.

    $val = "11.0.56.10000";

    i need to write regular expression which should match only "56" and print
    There are any number of ways to extract "56" using a regular expression from
    this string, and which would you would prefer depends on the general format of
    the strings like that that you expect.

    Can you describe how these strings look like?

    Please reply to the list.

    Regards,

    Shlomi Fish
    please suggest

    regards
    irfan


    --
    -----------------------------------------------------------------
    Shlomi Fish http://www.shlomifish.org/
    Funny Anti-Terrorism Story - http://shlom.in/enemy

    Live as if you were to die tomorrow. Learn as if you were to live forever.
    http://en.wikiquote.org/wiki/Mohandas_Gandhi (Disputed)

    Please reply to list if it's a mailing list post - http://shlom.in/reply .
  • Shawn H Corey at Sep 10, 2011 at 5:56 pm

    On 11-09-10 01:23 PM, Irfan Sayed wrote:
    i have following string.

    $val = "11.0.56.10000";

    i need to write regular expression which should match only "56" and print

    please suggest
    ( $val =~ /(56)/ ) && print $1;


    --
    Just my 0.00000002 million dollars worth,
    Shawn

    Confusion is the first step of understanding.

    Programming is as much about organization and communication
    as it is about coding.

    The secret to great software: Fail early & often.

    Eliminate software piracy: use only FLOSS.

    "Make something worthwhile." -- Dear Hunter
  • Rob Dixon at Sep 10, 2011 at 7:44 pm

    On 10/09/2011 18:23, Irfan Sayed wrote:
    hi,

    i have following string.

    $val = "11.0.56.10000";

    i need to write regular expression which should match only "56" and print

    please suggest
    I think you should forget about regular expressions and use split:

    my $sub = (split /\./, $val)[2];

    HTH,

    Rob
  • Timothy adigun at Sep 11, 2011 at 5:12 am
    Hi Irfan,
    You can use unpack:

    $val = "11.0.56.10000";
    $new_val=unpack("x5 A2",$val); # skip forward 6, get 2
    print $new_val # print 56;
  • Uri Guttman at Sep 11, 2011 at 6:09 am
    "ta" == timothy adigun writes:
    ta> You can use unpack:

    ta> $val = "11.0.56.10000";
    ta> $new_val=unpack("x5 A2",$val); # skip forward 6, get 2

    ta> print $new_val # print 56;

    unpack would be a poor choice if the number of digits in a field
    changes. pack/unpack are meant for use in fixed field records.

    uri

    --
    Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
    ------------ Perl Developer Recruiting and Placement Services -------------
    ----- Perl Code Review, Architecture, Development, Training, Support -------
  • Timothy adigun at Sep 11, 2011 at 9:13 am
    "ug" == Uri Guttman writes:
    ug> unpack would be a poor choice if the number of digits in a field
    ug> changes. pack/unpack are meant for use in fixed field records.

    That was a bad assumption on my side, I only considered the problem at
    hand, thinking unpack will be faster that substr.

    Thanks,
    timothy

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedSep 10, '11 at 5:23p
activeSep 11, '11 at 9:13a
posts7
users6
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase