Re: regex help please
- From: Mirco Wahab <wahab@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 21:52:12 +0100
Thus spoke Jerry (on 2006-12-28 21:44):
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
EndedEmp";
Don't do that, $_ is bound to stay with forever ;-)
(remove the 'my')
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;
You could split on non-blanks and capture the split-results, e.g.:
my $string = " Emp# EmpStatus MStatus BeganEmp EndedEmp ";
print map "[$_]\n", split /(\S+)/, $string;
prints here:
[ ]
[Emp#]
[ ]
[EmpStatus]
[ ]
[MStatus]
[ ]
[BeganEmp]
[ ]
[EndedEmp]
[ ]
("mapped" brackets added for clarity ...)
Regards
M.
.
- References:
- regex help please
- From: Jerry
- regex help please
- Prev by Date: regex help please
- Next by Date: Re: regex help please
- Previous by thread: regex help please
- Next by thread: Re: regex help please
- Index(es):
Relevant Pages
|