Re: regex help please



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.


.



Relevant Pages

  • Re: edit-replace function
    ... original search string (and if you paste the string from your message into ... original document by viewing the space characters with CTRL+* a space will ... The brackets are there only to ... Lewis Shanks wrote:> Jon: ...
    (microsoft.public.word.customization.menustoolbars)
  • Re: edit-replace function
    ... > original search string (and if you paste the string from your message into ... > original document by viewing the space characters with CTRL+* a space will ... The brackets are there only ... >> Replacing characters using wildcards" site suggests. ...
    (microsoft.public.word.customization.menustoolbars)
  • Re: Transfer Spreadsheet acExport - Table with added column wont export
    ... Here is the sub for that (Without brackets or brackets ... dim MyPath ... dim OldQueryName as string ... OldQueryname = QueryName ...
    (microsoft.public.access.formscoding)
  • Re: Using curly braces in a variable
    ... You will no longer have a string. ... Ah, so Tcl isn't failing, the thing you are calling is failing because ... expect the literal string "lindex" to appear in the data stream? ... Yes - I noticed the same thing with the curly brackets - the error ...
    (comp.lang.tcl)
  • Re: What Does This Mean?
    ... What do the brackets around "String" ... I don't see the point of using the brackets in this context. ... Now the code would compile just fine. ... There are no advanced students in Aikido - there are only ...
    (microsoft.public.dotnet.languages.vb)