[Linux-disciples] Subtitutions of all permutations

Adam Kessel linux-disciples@bostoncoop.net
Fri, 19 Sep 2003 21:19:45 -0700


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

Here's what I would do, but that's just me:

s/<img.*?((alt=3D|src=3D)[^ ]*).*?((alt=3D|src=3D)[^ ]*)(.*?)>/<img $1 $3 \=
/>/g;

On Fri, Sep 19, 2003 at 02:39:34PM -0400, Stephen R Laniel wrote:
> A Perl puzzler for y'all; maybe it's not as difficult as I seem to think
> it is:
>=20
> Suppose you have an HTML tag like the img tag that looks like so:
>=20
> <img alt=3D"blah" width=3D"blah" src=3D"foo" height=3D"gern" style=3D"geh=
" />
>=20
> You want to strip out everything except for the "alt" and the "src", but
> they could appear anywhere in the list of attributes. So in Perl
>=20
> s{<img(.*)alt=3D(".*") src=3D(".*")(.*)(/?)>}{<img src=3D$2 alt=3D$1 />}g;
>=20
> would work, but then you'd have to do another version of the same
> substitution where the src came first and the alt came second, right?
>=20
> In greater generality, I guess what I'm wondering is whether there's any
> way to say "If there's any permutation of [list of things], perform this
> substitution on it." Is there any way to do that?
>=20
> --=20
> ```All placebos are not the same,' Eli Lilly spokesman Giles French
>    said. `Pacifex is the only placebo that's green and shaped like a
>    triangle. Pacifex: A doctor gave it to you.''
>   -http://www.theonion.com/3936/news2.html
>=20
> _______________________________________________
> Linux-disciples mailing list
> Linux-disciples@bostoncoop.net
> http://bostoncoop.net/mailman/listinfo/linux-disciples

--=20
Adam Kessel
http://bostoncoop.net/adam

--DBIVS5p969aUjpLe
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/a9VhdTf3ZklQ6qYRAncnAJ9WiMqTM1nVwgSJ4eDVaVaG0msFTwCeIhPD
2R+IQbEhstPT9NSLPVV5buU=
=Kk3E
-----END PGP SIGNATURE-----

--DBIVS5p969aUjpLe--