Solved

Simple REGEX  -  Why does this not work?

Posted on 2002-05-09
3
162 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now