Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 27th, 2012, 08:46 AM
SeaFargo SeaFargo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 4 SeaFargo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 31 sec
Reputation Power: 0
RegEx: how to exclude a tag attribute from a match?

Hello to everybody.

I am not a programmer but a designer, and I am completing a purge of a big database of html files full of usefull tags.

I already know (it was suggested to me) how to strip a specific pair of tag with a specific attribute (class="ArticoloTesto"):

find: (?s)<p[ \t\r\n]+class="ArticoloTesto">(.+?)</p>
replace: \1

Now shoud be nice to find another two commands, if you can please help me. :-)

First:

The opposite of the mentionen command. I mean a way to strip all the P pair tags without the attribute class="ArticoloTesto". So strip P pair with other attribute + P pair without any attribute. All preserving the inside text.

So for exampre an original strings like:

<p class="OtherClass">Disposizioni sulle acque</p>
<p class="ArticoloTesto">Fonte: BOLLETTINO UFFICIALE<br>
DELLA REGIONE TRENTINO</p>
<p>test text</p>

Should became:

Disposizioni sulle acque
<p class="ArticoloTesto">Fonte: BOLLETTINO UFFICIALE<br>
DELLA REGIONE TRENTINO</p>
test text


Second:

How to replace a specific pair tag, with and without a specific attribute, with another tag?

Ex:

from: <span class="ArticoloTesto">same text</span>
to: <p class="ArticoloTesto">same text</p>


Thank you in advance for any of your replay, anyway.

ps: I am useing this command on advanced find and replace software based on a perl engine regex. Ultra Edit in particulary.

Thank you so much.

Raf.

Reply With Quote
  #2  
Old April 28th, 2012, 12:32 AM
abareplace abareplace is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 29 abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 8 h 25 m 9 sec
Reputation Power: 0
Hello, Raf,

1) <p> tag without "ArticoloTesto" class:

Code:
find: <p(?![ \t\r\n]+class="ArticoloTesto").*?>(.+?)</p>
replace: \1


I'm not sure if UltraEdit supports lookahead, but it works in PHP and in my search-and-replace tool.

2) change <span class="ArticoloTesto"> to <p class="ArticoloTesto">

Code:
find: <span[ \t\r\n]+class="ArticoloTesto">(.+?)</span> (the same as in your example)
replace: <p class="ArticoloTesto">\1</p>

Reply With Quote
  #3  
Old April 30th, 2012, 05:14 AM
SeaFargo SeaFargo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 4 SeaFargo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 31 sec
Reputation Power: 0
Smile

Thank you very much, abareplace :-)

I was able answer my second question.. I realize it some minutes after my post but ...
...your answer of my first, most important, question was so so utile!!

<p(?![ \t\r\n]+class="ArticoloTesto").*?>(.+?)</p>

Great!

Thanks one more time ;-)

Raf.

Reply With Quote
  #4  
Old April 30th, 2012, 05:52 AM
SeaFargo SeaFargo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 4 SeaFargo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 31 sec
Reputation Power: 0
How to copy text between a tag and paste into another tag.

A last question, if I am not bothering you.

I really have quite finished the work, but I still want some step forward.

I have for example this HTML tag:

<title>alwaysthesame</title>
and later
<p class="ArticoloTitoloPrincipale">different text for each file</p>

I would like to copy different text for each file and paste it over alwaysthesame.

In that way I can have a title corresponding to the text inside the only one tag p class="ArticoloTitoloPrincipale" of the page (wich is the title of the document, as you can imagine).

If it's not too complex, I wonder to can correct the absence of a corresponding title in each of my html files.

Thank you in any case :-)

Raf.

Reply With Quote
  #5  
Old April 30th, 2012, 06:04 AM
abareplace abareplace is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 29 abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level)abareplace User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 8 h 25 m 9 sec
Reputation Power: 0
Please try:

Code:
Search for: (?s)<title>.*?</title>(.*?)<p class="ArticoloTitoloPrincipale">(.*?)</p>

Replace to: <title>\2</title>\1<p class="ArticoloTitoloPrincipale">\2</p>

Reply With Quote
  #6  
Old April 30th, 2012, 09:07 AM
SeaFargo SeaFargo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 4 SeaFargo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 31 sec
Reputation Power: 0
Smile Thank you so much!!!

Yes, abareplace.

It works perfectly!!

It's a very complex command for me (backreferences seems not easy..). I've tried a lot before asking help out there, but I really have no skills on it.. I am a graphic designer and photographer in Italy.

I have to admit that Perl knowlage gives a lot o freedom!!

My best regards.

Raffaele.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > RegEx: how to exclude a tag attribute from a match?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap