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
Solved

Simple REGEX  -  Why does this not work?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

840 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