Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Getting Started / July 2009



Tip: Looking for answers? Try searching our database.

Need help w/ substitute ie. s/x/y/

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis G. Wicks - 03 Jul 2009 23:39 GMT
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>

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

Obviously I am getting further away so no need to try and
correct the above.

Any help will be greatly appreciated!

Many TIA!!
Dennis

Signature

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

Gunnar Hjalmarsson - 04 Jul 2009 01:34 GMT
> Greetings;
>
[quoted text clipped - 13 lines]
> <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.

Signature

Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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

Dennis G. Wicks - 04 Jul 2009 02:10 GMT
Gunnar Hjalmarsson wrote the following on 07/03/2009 07:34 PM:
>> Greetings;
>>
[quoted text clipped - 28 lines]
> 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.

Signature

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

Eric Veith - 06 Jul 2009 10:35 GMT
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" <dgwicks@gmail.com> wrote on 07/04/2009 03:10:45 AM:

> From:
>
[quoted text clipped - 16 lines]
> >>
> >> 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)------------------->|<-------------
[quoted text clipped - 12 lines]
> >
> >> I am having no luck at all. Here is my last attempt, which produces no

> >> change at all!!
> >>
[quoted text clipped - 20 lines]
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/

Signature

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

Dennis G. Wicks - 06 Jul 2009 16:30 GMT
Eric Veith wrote the following on 07/06/2009 04:35 AM:
> Dennis,
>
[quoted text clipped - 81 lines]
>>
>> --
Thanks! That is a little clearer now!

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.