Re: regex help please



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
.



Relevant Pages

  • RE: how to regex or
    ... Jerry ... Subject: how to regex or ... Then maybe I'm not understanding what you're asking. ... print $string; ...
    (perl.beginners)
  • RE: how to regex or
    ... Then maybe I'm not understanding what you're asking. ... print $string; ... Subject: how to regex or ... Jerry ...
    (perl.beginners)
  • RE: Regex c code
    ... Jerry ... As far as I can see you aren't missing anything. ... > Subject: Regex c code ... > I want to get the function name from a string of c code: ...
    (perl.beginners)
  • RE: how to regex or
    ... Jerry ... Subject: how to regex or ... I am trying to swap all the '||' in a string to or: ...
    (perl.beginners)
  • Re: Fastest way to search a string for the occurance of a word??
    ... but the OP's question was what's the "Fastest way to search a string ... in all the tests I did here, the Regex was by far superior. ... However, of course, if you've got new regular expressions all ... Sure - but just that extra Match object could be relevant if the search ...
    (microsoft.public.dotnet.languages.csharp)