CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Complex regex help? Look if you dare!

 



jaquemon
New User

May 23, 2007, 9:59 AM

Post #1 of 5 (4563 views)
Complex regex help? Look if you dare! Can't Post

Below is what I have so far and this is what I am looking for.
I have tried a multitude of combinations of regex's, all to no avail for what I am trying to do. I am trying to pull out a paragraph of information based on the following conditions:
1. The user specified pattern, $agent, will appear at the top of the first paragraph. If this is going to be a valid match, $agent must also appear at the end of the second paragraph.
2. The problem I am having is differentiating between the two. By this I mean some paragraphs will have the $agent in the beginning and at the end. The only difference between a valid match and junk is there is a blank line between the two. I have attempted to use ^$ (blank line) which works for a blank line by its self, but whenever I try to use it concatenated with anything else, it fails the test.

Any help is greatly appreciated and if anyone has any ?'s feel free to ask. I hope this is easy for someone else. Thanks


Code
while (<IN>)  
{
# where $agent is a pattern user speciefies
if ( /[0-9].$agent\.waw/../\d\.\d(^$)(.*)type \- $agent\- \?{2} false/)
{
print OUT $_;
}
}



miller
User

May 25, 2007, 10:04 AM

Post #2 of 5 (4553 views)
Re: [jaquemon] Complex regex help? Look if you dare! [In reply to] Can't Post

If you're going to include the anchors ^ and $ in the middle of your regex, then you have to include the 'm' modifier at the end of your regex. This is what lets the anchors match the start and end of any line versus just the start and end of the entire string. Read about it here:

http://perldoc.perl.org/perlre.html

- Miller


KevinR
Veteran


May 25, 2007, 10:39 AM

Post #3 of 5 (4550 views)
Re: [miller] Complex regex help? Look if you dare! [In reply to] Can't Post

welcome to the forum Miller Wink

This is the same guy that was posting on tek-tips
-------------------------------------------------


miller
User

May 25, 2007, 3:05 PM

Post #4 of 5 (4547 views)
Re: [KevinR] Complex regex help? Look if you dare! [In reply to] Can't Post

Thanks Kev. Just swinging by for a visit :)

- M


KevinR
Veteran


May 25, 2007, 3:35 PM

Post #5 of 5 (4545 views)
Re: [miller] Complex regex help? Look if you dare! [In reply to] Can't Post

Cool, nice to have ya. This forum is pretty slow but generally gets a few questions posted per week.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives