Regular expressions

I’m having trouble with a simple match:

line
=> “
line =~ /(<img .*>)/
=> nil

Shouldn’t “.” match anything other than “\n”?
Can anyone see what I’m doing wrong?

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

I’m having trouble with a simple match:

line
=> “
line =~ /(<img .*>)/
=> nil

Shouldn’t “.” match anything other than “\n”?
Can anyone see what I’m doing wrong?

But you have ., which matches a literal period.

···

At 5:38 +0900 1/22/03, Daniel Carrera wrote:


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

In addition to the . as mentioned early, .* is greedy, so if
you have:

then /(<img .*>)/ will give $1 = ‘

You want either /(<img [^>]>)/ or /(<img .?>)/, the latter being
non-greedy.

···

Daniel Carrera (dcarrera@math.umd.edu) wrote:

I’m having trouble with a simple match:

line
=> “
line =~ /(<img .*>)/
=> nil

Shouldn’t “.” match anything other than “\n”?
Can anyone see what I’m doing wrong?


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Hi –

···

On Wed, 22 Jan 2003, Daniel Carrera wrote:

I’m having trouble with a simple match:

line
=> “
line =~ /(<img .*>)/
=> nil

Shouldn’t “.” match anything other than “\n”?
Can anyone see what I’m doing wrong?

You’ve escaped your . so it’s a literal . , which then
isn’t found. You have to remove the ''.

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Okay, now I feel stupid. Thanks.

···

On Wed, Jan 22, 2003 at 05:42:07AM +0900, Paul DuBois wrote:

But you have ., which matches a literal period.


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137