help in regular expression

help in regular expression

am 10.09.2011 19:23:31 von Irfan Sayed

--0-1059656760-1315675411=:2887
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

hi, i have following string. $val =3D "11.0.56.10000"; i ne=
ed to write regular expression which should match only "56" and print =0A=
=0Aplease suggest  =0Aregards=0Airfan
--0-1059656760-1315675411=:2887--

Re: help in regular expression

am 10.09.2011 19:47:18 von Shlomi Fish

Hi Irfan,

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

> hi,
>=20
> i have following string.=20
>=20
> $val =3D "11.0.56.10000";
>=20
> i need to write regular expression which should match only "56" and print=
=20
>=20

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 
>=20
> regards
> irfan



--=20
------------------------------------------------------------ -----
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.
â€=94 http://en.wikiquote.org/wiki/Mohandas_Gandhi (Disputed)

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: help in regular expression

am 10.09.2011 19:56:31 von Shawn H Corey

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

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: help in regular expression

am 10.09.2011 21:45:02 von Rob Dixon

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

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: help in regular expression

am 11.09.2011 07:12:26 von timothy adigun

--0016e6586168d8d20404aca37466
Content-Type: text/plain; charset=ISO-8859-1

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;

--0016e6586168d8d20404aca37466--

Re: help in regular expression

am 11.09.2011 08:09:31 von Uri Guttman

>>>>> "ta" == timothy adigun <2teezperl@gmail.com> 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 -------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: help in regular expression

am 11.09.2011 11:13:24 von timothy adigun

--00504502c66092a77c04aca6d2ec
Content-Type: text/plain; charset=ISO-8859-1

>>>>>> "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

--00504502c66092a77c04aca6d2ec--