Need Regular Expression

I need to parse this line:

\\DP_DEVELOPMENT\NEC  SuperScript 860^NEC  SuperScript 860^LPT1:~

into:

\\DP_DEVELOPMENT\NEC  SuperScript 860
NEC  SuperScript 860
LPT1:

so that each line will be in $1, $2 and $3.
paulcaAsked:
Who is Participating?
 
maneshrConnect With a Mentor Commented:
two solutions. one using split (^ as de-lim) and other using pattern.

===========test.pl
#!/usr/bin/perl

$var="\\DP_DEVELOPMENT\NEC  SuperScript 860^NEC  SuperScript 860^LPT1:~ ";

print "Before ",$var,"\n";

####### Method 1 #############3
@tmp=split(/\^/,$var);
foreach(@tmp){
  print $_,"\n";
}

####### Method 2 #############3
$var=~ /(.*)\^(.*)\^(.*)/;
print "After ",$1,"\n",$2,"\n",$3,"\n";
0
 
RobWMartinCommented:
Try this:

s/([^^]+)^([^^]+)^([^~]+)~/\1\n\2\n\3/

then $1, $2, and $3 have the segments.
0
 
RobWMartinCommented:
maneshr, you are a show off :)

0
All Courses

From novice to tech pro — start learning today.