Re: regex help please



Paul,

Basicly that is the code except for reading a file:

open ( FI, "$work_path\\$form_file" ) or die "Couldn't open
$work_path\\$form_file";
my @text = <FI>;
close FI;
Yes this is wrong "my $_", I was using "my $str" at first.

This is just a simple way to list my results for debuging my code:
print "parm: *1 $1*2 $2*3 $3*4 $4*6 $6*7 $7*8
$8*$9*$10*$11*$12*$_*<br>\n";

Nothing major going on!

Thanks,

Jerry



"Paul Lalli" <mritty@xxxxxxxxx> wrote in message
news:1167339165.614399.257270@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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
EndedEmp";

$_ cannot be lexicalized. Please post real code. Have you read the
posting guidelines that are posted here twice a week? They contain
invaluable information on how to create a good posting that is likely
to be answered.

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 don't have a clue what this means. What does "all the spaces as a
word between the words" mean? Please post desired output along with
your sample input. This is another thing that's in those guidelines.

I have started with:

/\s+(\w+)\s+/g;

print "parm: *1 $1*2 $2*3 $3*4 $4*6 $6*7 $7*8
$8*$9*$10*$11*$12*$_*<br>\n" ;

And how does the result of this do or not do what you want? Please
post actual output along with desired output and sample input. Again,
this is in the posting guidelines.

As a hunch, I'd say you want to use the split function, splitting on
whitespace, and capturing the delimiter with parentheses, so that the
delimiters are also returned. See
perldoc -f split

And then create a short-but-complete script that demonstrates your best
attempt, along with sample input and output that demonstrates what you
want, what you got, and how they differ.

Paul Lalli



.



Relevant Pages

  • Re: regex help please
    ... post actual output along with desired output and sample input. ... this is in the posting guidelines. ... whitespace, and capturing the delimiter with parentheses, so that the ...
    (comp.lang.perl.misc)
  • Re: regex help please
    ... post actual output along with desired output and sample input. ... this is in the posting guidelines. ... whitespace, and capturing the delimiter with parentheses, so that the ...
    (comp.lang.perl.misc)
  • Re: split field by delimiter "|" but data have "|"
    ... below in output file ... that's your sample input - what would the desired output be given ... Field 5 HK PROD ...
    (comp.lang.awk)
  • Re: how to match or detect alphanumeric including - or spaces through out
    ... short-but-complete script, along with sample input, desired output, and ... to include at least a couple strings that should match and a couple ...
    (comp.lang.perl.misc)