--Hc9bqgA2GpWXzMYS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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

> I'm having trouble with a simple match:
>=20
> >> line
> =3D> "<img src=3D'a.jpg' />"
> >> line =3D~  /(<img \.*>)/
> =3D> nil
>=20
> Shouldn't "." match anything other than "\n"?
> Can anyone see what I'm doing wrong?

In addition to the \. as mentioned early, .* is greedy, so if
you have:
<a href=3D"#foo"><img src=3D"bar.png"></a>
then /(<img .*>)/ will give $1 =3D '<img src=3D"bar.png"></a>'

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

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


--Hc9bqgA2GpWXzMYS
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iD8DBQE+LbHOMypVHHlsnwQRAo98AJ4ju+QTGqgkdmEWwrD4wsBL148zKgCfXnpL
nJIfW9reS+oBf6oRWBuEq/Y=
=Ij5l
-----END PGP SIGNATURE-----

--Hc9bqgA2GpWXzMYS--

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

> I'm having trouble with a simple match:
>=20
> >> line
> =3D> "<img src=3D'a.jpg' />"
> >> line =3D~  /(<img \.*>)/
> =3D> nil
>=20
> Shouldn't "." match anything other than "\n"?
> Can anyone see what I'm doing wrong?

In addition to the \. as mentioned early, .* is greedy, so if
you have:
<a href=3D"#foo"><img src=3D"bar.png"></a>
then /(<img .*>)/ will give $1 =3D '<img src=3D"bar.png"></a>'

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

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iD8DBQE+LbHOMypVHHlsnwQRAo98AJ4ju+QTGqgkdmEWwrD4wsBL148zKgCfXnpL
nJIfW9reS+oBf6oRWBuEq/Y=
=Ij5l
-----END PGP SIGNATURE-----