#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep 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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep 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>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep 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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep 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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep 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>
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo