• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Simple REGEX - Why does this not work?

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
jgore
Asked:
jgore
1 Solution
 
iddo_levinCommented:
use this:

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

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

0
 
ozoCommented:
To make the regex work, use the /s modifier
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now