Oh, and assertatation are lookups like this one: (?!R_) (?=[^_])
But so far they are all wrong.
Main Topics
Browse All TopicsHi,
I have the following lines.
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
I know the pattern for NR_(expression) or R_(expression) and for each given line
I need to store the first set of words and the word with the expression into variables
So for line 1 if my pattern is "what" I want to store -abcd, "x" and R_what into 3 variables
and for line 2 if my pattern is "carw" I want to store -abcd and NR_carw into 2 variables
for line 3 if my pattern is "abdcd" then i want to store -abcd,opt1 and NR_abdcd into 3 variables
so on,
Basically I want to store all the words till R_* or NR_* and finally store the
(R_* or NR_*) whichever matches my pattern.
This is what I am doing and for some reason it is not working any suggestions on how to do it
if ($Data[$k]=~/^(-\S+)\s+(\S
{
print "Debug4 \n";
$xyz1 = $1;
$xyz2 = $2;
$xyz3 = $3;
Finally I also want to be able to figure out if any of my words have double quotes and
store the values between quotes.
so for line 1 -abcd is followed by "x" which is a non (R_* or a NR_*) word and since it
has double quotes I want to save only x to an variable.
for line 2 -abcd is not followed by any non (R_* or a NR_*) so i do nothing
for line 3 -abcd is followed by opt1 which does have quotes so I want to save opt1 to an
variable.
x
Thnak you
-V
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
How about this work around:
$lines = <<EOL;
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
EOL
$pattern = "carw";
@Data = split("\n", $lines);
for($k=0;$k<@Data;$k++){
#print $Data[$k]."\n";
if ($Data[$k]=~/^(-\w+)\W+(\w
$xyz1 = $1;
$xyz2 = $2;
$xyz3 = $3;
$_ = $xyz2;
$xyz2 = "" if (/_/);
print "1:$xyz1 2:$xyz2 3:$xyz3\n";
}
}
And if you like to have value three shifted if value2 is empty, then try this:
$lines = <<EOL;
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
EOL
$pattern = "carw";
@Data = split("\n", $lines);
for($k=0;$k<@Data;$k++){
#print $Data[$k]."\n";
if ($Data[$k]=~/^(-\w+)\W+(\w
$xyz1 = $1;
$xyz2 = $2;
$xyz3 = $3;
if($xyz2 =~ /_/){
$xyz2 = $xyz3;
$xyz3 = "";
}
print "1:$xyz1 2:$xyz2 3:$xyz3\n";
}
}
Nice expression :)
$lines = <<EOL;
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
EOL
$pattern = "carw";
@Data = split("\n", $lines);
for($k=0;$k<@Data;$k++){
@xyz = map{/^"?(\S*?)"?$/}(split/
foreach (@xyz){
print "$_\t";
}
print "\n";
}
Or into vars like this:
$lines = <<EOL;
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
EOL
$pattern = "carw";
@Data = split("\n", $lines);
for($k=0;$k<@Data;$k++){
@xyz = map{/^"?(\S*?)"?$/}(split/
($xyz1,$xyz2,$xyz3) = @xyz;
print "$xyz1\t$xyz2\t$xyz3\n";
}
Nothing has happened on this question in more than 5 weeks. It's time for cleanup!
My recommendation, which I will post in the Cleanup topic area, is to
split points between ZeroPage [400 pts] and ozo [100 pts].
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: ZeroPagePosted on 2003-12-18 at 01:50:32ID: 9963047
I am working on the assertation that second word is not a R_ option, but so far I did not succeed.
+)\W+.+\W+ (\w{1,2}_$ pattern)/g i){
My actual state is this:
$lines = <<EOL;
-abcd "x" NR_name NR_abdcd NR_carw R_what R_noway R_word - line 1
-abcd R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
-abcd opt1 R_name NR_abdcd NR_carw R_what R_noway R_word - line 2
EOL
$pattern = "carw";
@Data = split("\n", $lines);
for($k=0;$k<@Data;$k++){
#print $Data[$k]."\n";
if ($Data[$k]=~/^(-\w+)\W+(\w
$xyz1 = $1;
$xyz2 = $2;
$xyz3 = $3;
print "1:$xyz1 2:$xyz2 3:$xyz3\n";
}
}