Paul Lalli said:
I have the following regex. It is matching what I want( /BIG/TRUCK),
but it is also included the leading space. Is there anyway to
suppress the leading space.
\b[^"|']/\w+/\w+\b
String:
TYPE /BIG/TRUCK
I don't understand your question. You're very specifically looking
for "word boundary; anything other than double quote, vertical-bar, or
single quote; slash; one or more word characters; slash; one or more
word characters; word boundary". The space character matches the
"anything other than..." portion of that. If you don't want to match
that space character, why are you putting that token in there?
To put it another way: Please post a SHORT but COMPLETE script that
demonstrates both what you're doing, and the output that demonstrates
what you want to do.
Paul Lalli
Jerry, and all other people with Regex type questions;
If you read the posting guidelines that are posted frequently
and easily googleable for this news group, you'll see that what
Paul means by "SHOFT but COMPLETE program"
is something like this:
==cut==
use warnings; # see perldoc warnings
use strict; # see perldoc strict
while (<DATA>){ # get a line from below __DATA__ in to $_ default var
chomp;
my ($saved) = ( m
\b[^"|']/\w+/\w+\b): );
print "Line $. is '$_', saved section is '$saved'\n";
}
__DATA__
TYPE /BIG/TRUCK
ECHO /SMALL/CAR
==cut==
# Here is the output I have:
Line 1 is 'TYPE /BIG/TRUCK', saved section is ' /BIG/TRUCK'
Line 2 is 'ECHO /SMALL/CAR', saved section is ' /SMALL/CAR'
# Here is the output I desire:
Line 1 is 'TYPE /BIG/TRUCK', saved section is '/BIG/TRUCK'
Line 2 is 'ECHO /SMALL/CAR', saved section is '/SMALL/CAR'
######
With the above type of data, it is easy for anyone to
copy and paste your complete program with DATA and run it
to demonstrate. Plus, it helps you find the problem yourself.
Hey look, if I follow Paul's adice and move the ( to after
the [] section, it generates the desired output.
was my ($saved) = ( m
\b[^"|']/\w+/\w+\b): );
now my ($saved) = ( m:\b[^"|'](/\w+/\w+\b): );
^------>(