Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex help 1

Status
Not open for further replies.

Zoom1234

Programmer
Oct 30, 2003
116
BE
Hi,
I have following strings
Code:
string1: //ap21cnedc22/retail/main/eCommerce/Development/Release1_updated_Content/shop/production/WORKAREA/Application_Development
string2: //ap21cnedc22/retail/main/eCommerce/Development/Release1_updated_Content/shop/production/WORKAREA/Application_Development/test/test1
The string will always have /main and WORKAREA in it.
I have to extract the string which is next level of WORKAREA
i.e.
/main/eCommerce/Development/Release1_updated_Content/shop/production/WORKAREA/Application_Development
I have tried following regex, but it works only for string2 and not for string1
Code:
$string =~ m!(.*)/(.*)/(main.*)/(WORKAREA/.*?)/.*$!;
$output = '/'.$3.'/'.$4 ;
How can i acheive the required output?

 
you've over complicated your regexp:

Code:
my $string1 = '//ap21cnedc22/retail/main/eCommerce/Development/Release1_updated_Content/shop/production/WORKAREA/Application_Development';
my $string2 = '//ap21cnedc22/retail/main/eCommerce/Development/Release1_updated_Content/shop/production/WORKAREA/Application_Development/test/test1';
for ($string1,$string2) {
   m!(/main.*WORKAREA/\w*)!;
   print "$1\n";
}


- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top