Re: regexp matching across newlines

2002-07-23 Thread David T-G
Bob, et al -- ...and then Bob Showalter said... % % > -Original Message- % > From: David T-G [mailto:[EMAIL PROTECTED]] ... % > Whoops! No it won't -- .* is greedy! % > % > You need something more like ... % > /(p1)[^(p2)]*(p2)/g ; ... % This does not match on input data like: % %

RE: regexp matching across newlines

2002-07-23 Thread Bob Showalter
> -Original Message- > From: David T-G [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 22, 2002 8:13 PM > To: perl beginners > Cc: David Newman > Subject: Re: regexp matching across newlines > > > David -- > > ...and then David Newman said... > % &g

Re: regexp matching across newlines

2002-07-22 Thread Shawn
> I've tried with /g alone and also with /gs, /gm, and /gms. As long as /s is > one of the modifiers I do match one instance, but in no case do I match > multiple instances. Weird. Give this a try... while () { if(m/(p1).*?(p2)/gs) { print "match! found $1 and $2.\n"; } } The problem is

Re: regexp matching across newlines

2002-07-22 Thread David T-G
David -- ...and then David Newman said... % % > Yes, but your *. should be .* to work. When you have % % Sorry, typo. It is .* in the code! Ah. Well, then, there's more... % ... % > % Again, my goal is to match each instance of /(p1)*anything*(p2)/. % > % > I should think that % > % > u

RE: regexp matching across newlines

2002-07-22 Thread David Newman
> Yes, but your *. should be .* to work. When you have Sorry, typo. It is .* in the code! > % If I do (for example) "p1 p2 p1 p2\n\np1 p2", shouldn't the > while loop match > % on 3 instances? If not, what should I use to match each instance? > > Now that it's all one big line, you need /g to

Re: regexp matching across newlines

2002-07-22 Thread David T-G
David -- ...and then David Newman said... % % many thanks... Here's hoping I can help, too :-) % % > Set $/ to undef instead. Good. % > ... % > > if (m/(p1)*.(p2)/ms) { ... % > When $/ is "", it's like the regex /\n{2,}/. % % wouldn't this have worked before, since the pattern was

RE: regexp matching across newlines

2002-07-22 Thread David Newman
many thanks... > > >$/ = ''; > > Set $/ to undef instead. > > >while() { > > if (m/(p1)*.(p2)/ms) { > > print "match! I found $1 and $2\n."; > > } > >} this does work, but... > > When $/ is "", it's like the regex /\n{2,}/. wouldn't this have worked before, since t

Re: regexp matching across newlines

2002-07-22 Thread John W. Krahn
David Newman wrote: > > Consider a file containing this pattern: > > p1 > p2 > > I can match for p1 and p2 like this: > > $/ = ''; perldoc perlvar You are setting $/ to paragraph mode which is why the second example doesn't work. > while() { > if (m/(p1)*.(p2)/ms) {

Re: regexp matching across newlines

2002-07-22 Thread Jeff 'japhy' Pinyan
On Jul 22, David Newman said: >$/ = ''; Set $/ to undef instead. >while() { > if (m/(p1)*.(p2)/ms) { > print "match! I found $1 and $2\n."; > } >} When $/ is "", it's like the regex /\n{2,}/. If it's undef, then slurps the entire file at once. -- Jeff "japhy" Piny