Solved

Simple REGEX  -  Why does this not work?

Posted on 2002-05-09
3
179 Views
Last Modified: 2010-03-05
Simple REGEX:
Why does this not work? All I want is to grab the
first three lines in the first three variables and then
everything else in the fourth variable.
When I try to use ^ or $ (beginning or end of line chars)
it really doesn't work at all!
The Regex should use \n as seperation char.

Thanks for any help!

--------------- snip ------------------


#!\perl\bin\perl.exe

my $element =
"LineOne
LineTwo
LineThree

Line here
Line this and that
Line some more

";

my ($var1,$var2,$var3,$var4) = ($element =~ m/(.*?)\n(.*?)\n(.*?)\n(.*)/);

print "Line1=".$var1."\n";
print "Line2=".$var2."\n";
print "Line3=".$var3."\n";
print "TheRest=".$var4."\n\n";

0
Comment
Question by:jgore
3 Comments
 

Accepted Solution

by:
iddo_levin earned 100 total points
ID: 7000056
use this:

@lines = split (/\n/, $element, 4);
0
 

Author Comment

by:jgore
ID: 7000103

Thanks!  Works good.
I was so busy trying to make rexgex work I forgot about
split ;-)

0
 
LVL 84

Expert Comment

by:ozo
ID: 7000496
To make the regex work, use the /s modifier
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question