RE: Extract the desired value from a regex




Refer this code

use warnings;
use strict;
my $string = "M W 8:00AM - 10:20";
$string =~ /(^M)\s(W)\s(\d{1,2}:\d{2}[A|P]M\s-\s\d{2}:\d{2})/;
#print "$1\n$2\n$3"
my $time = $3;
my $days = join(",",$1,$2);
print "time = $3\n";
print "days = $days"


Output:
time = 8:00AM - 10:20
days = M,W

-----Original Message-----
From: Manasi Bopardikar [mailto:manasi_bopardikar@xxxxxxxxxxxxxxxx]
Sent: Friday, July 18, 2008 10:06 AM
To: 'sanket vaidya'
Subject: RE: Extract the desired value from a regex

String is
M W 8:00AM - 10:20
I want to put M,W in days array
8:00AM - 10:20 in the time array

Thanks
-----Original Message-----
From: sanket vaidya [mailto:sanket.vaidya@xxxxxxxxx]
Sent: Friday, July 18, 2008 9:58 AM
To: 'Manasi Bopardikar'
Cc: beginners@xxxxxxxx
Subject: RE: Extract the desired value from a regex

You want to capture character "?" means zero or one time repetition. To
disable the effect of such characters use \Q & to enable the effect use \E.

So try $array[3]=~/[M|T|W|TR|F]\s[M|T|W|TR|F]\s(.*\Q?\E)/;

If this doesn't work send the entire string from which you want to capture &
what to capture?

Thanks & Regards,
Sanket Vaidya
Patni Computer Systems Limited


-----Original Message-----
From: Manasi Bopardikar [mailto:manasi_bopardikar@xxxxxxxxxxxxxxxx]
Sent: Friday, July 18, 2008 9:52 AM
To: 'sanket vaidya'
Subject: RE: Extract the desired value from a regex

Can you please explain it a little more/

-----Original Message-----
From: sanket vaidya [mailto:sanket.vaidya@xxxxxxxxx]
Sent: Friday, July 18, 2008 9:47 AM
To: 'Manasi Bopardikar'
Cc: beginners@xxxxxxxx
Subject: RE: Extract the desired value from a regex

$1 does not work because you are using metacharacter "?" in regex. Use \Q &
\E to capture.

Thanks & Regards,
Sanket Vaidya
Patni Computer Systems Limited
A 78/9, GIDC, Electronics Estate
Sector - 25, Gandhinagar - 382 016
Gujarat, India
Tel: 91-79-23240905 Ext: 243


-----Original Message-----
From: Manasi Bopardikar [mailto:manasi_bopardikar@xxxxxxxxxxxxxxxx]
Sent: Friday, July 18, 2008 9:22 AM
To: beginners@xxxxxxxx
Subject: Extract the desired value from a regex

Hi,

I have a regex --- $array[3]=~/[M|T|W|TR|F]\s[M|T|W|TR|F]\s(.*?)/;



I want to extract the value of expression highlighted in red.Is there any
way to do it.

-I tried $1 does not work.Why doesn't it work I do not understand.

Is there any other way to do it.





Thanks and Regards,

Manasi Bopardikar|s/w Engineer|Persistent SystemsLtd

(+91)(020)(30234497)|9767218759

manasi_bopardikar@xxxxxxxxxxxxxxxx




DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.


http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to whom this
message was originally addressed. Any review, e-transmission dissemination
or other use of or taking of any action in reliance upon this information by
persons or entities other than the intended recipient is prohibited. If you
have received this e-mail in error kindly delete this e-mail from your
records. If it appears that this mail has been forwarded to you without
proper authority, please notify us immediately at netadmin@xxxxxxxxx and
delete this mail.
_____________________________________________________________________


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.


http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to whom this
message was originally addressed. Any review, e-transmission dissemination
or other use of or taking of any action in reliance upon this information by
persons or entities other than the intended recipient is prohibited. If you
have received this e-mail in error kindly delete this e-mail from your
records. If it appears that this mail has been forwarded to you without
proper authority, please notify us immediately at netadmin@xxxxxxxxx and
delete this mail.
_____________________________________________________________________


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.


http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netadmin@xxxxxxxxx and delete this mail.
_____________________________________________________________________
.