Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple REGEX  -  Why does this not work?

Posted on 2002-05-09
3
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
iddo_levin earned 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

721 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