Re: regex help please
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 21:04:51 GMT
Jerry wrote:
It has been a while that I have done any regex. What I am trying to do is
break down a string like the following:
my $_ = " Emp# EmpStatus MStatus BeganEmp
You can't use my() on one of Perl's special variables like $_.
EndedEmp";
I do not know many words will be in $_ or if there will be spaces at the
front of $_ or not.
Along the getting the words, I need to get all the spaces as a word between
the words and at the end as well.
I have started with:
/\s+(\w+)\s+/g;
With your example above that will only match the two strings " Emp# "
and " MStatus ".
print "parm: *1 $1*2 $2*3 $3*4 $4*6 $6*7 $7*8
$8*$9*$10*$11*$12*$_*<br>\n" ;
Maybe you want something like this:
$_ = " Emp# EmpStatus MStatus BeganEmp EndedEmp";
my @fields = split;
my $count;
print join '*', 'parm: ', map( ++$count . " $_", @fields ), $_, "<br>\n";
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- regex help please
- From: Jerry
- regex help please
- Prev by Date: Re: regex help please
- Next by Date: Re: regex help please
- Previous by thread: Re: regex help please
- Next by thread: FAQ 5.7 How can I manipulate fixed-record-length files?
- Index(es):
Relevant Pages
|