Dennis,

Gunnar is right, you're misusing character classes.

A correct regular expression could look like this (using /x and Perl 5.10's
named capture buffers):

/(?<img_link><a[^>]+>)
(?<img><img[^>]+></a>)
\s,
(?<msg_link><a[^>]+><font[^>]+>)
(?<msg>[^<]+)
</font></a>
/x

I did not test that, but I guess you'll get the meaning. :-)

HTH

            -- Eric


"Dennis G. Wicks" <dgwi...@gmail.com> wrote on 07/04/2009 03:10:45 AM:

> From:
>
> "Dennis G. Wicks" <dgwi...@gmail.com>
>
> To:
>
> beginners@perl.org
>
> Date:
>
> 07/04/2009 03:11 AM
>
> Subject:
>
> Re: Need help w/ substitute ie. s/x/y/
>
> Gunnar Hjalmarsson wrote the following on 07/03/2009 07:34 PM:
> > Dennis G. Wicks wrote:
> >> Greetings;
> >>
> >> I have a file of 100+ records like the following. I hope the line wrap

> >> doesn't mess things up too much.
> >>
> >>> <a href="http://www.ten.com/"; target="_blank">|<img src="/022.jpg"
> >>> border="0"></a>| ,<a href="http://www.ten.com/"; target="_blank"><font

> >>> size="1">|Link Text Message|</font></a>
> >>> <---------------------($1)------------------->|<-------------
> ($2)---------------->|<---------------------------------
> ($3)------------------------>|<------($4)----->|<<trash>>>>
> >>>
> >>
> >> I have inserted | where I want to split them and indicated by
> >> <--($n)--> below the record what var I think they will go to.
> >>
> >> I want to reformat them as $1$4$2 so they look like this:
> >>
> >> <a href="http://www.ten.com/"; target="_blank">Link Text Message<img
> >> src="/022.jpg" border="0"></a>
> >
> >     s#^(.+?)(<img.+?</a>).+?<font.+?>([^<]+).*#$1$3$2#
> >
> >> I am having no luck at all. Here is my last attempt, which produces no

> >> change at all!!
> >>
> >>> perl -i -p -e 's/^([^<img]+)(<img.+\/a> )(,.+1\">)(.+<)/$1$4$2/'
FHG.tst
> >
> > Among other things you need to read up on character classes. They deal
> > with characters, not strings.
> >
> > Does the file only consist of such records, one on each line, and with
> > identical markup? If not, trying to do it with one substitution is a
> > crazy idea. If it's a real world thing, you most likely should use an
> > HTML parser.
> >
> As I said,
>    "I have a file of 100+ records like the following."
>
> Yes, all records are the same format. It is not an html
> file, and I doubt it merits the complexity of any HTML parser.
>
> Thanks.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to