0

I have a Html file containing lists, images and span tags I want to bring name of the images and text between the span tag and remove the rest , I think that there is some Reg Exp that can do this task but I can't figure out how , could you please help , this is a part from my file :

           <a href="text/tirette-a-cable-boite-de-vitesse-manuelle-15187" class="ga-click js--header__cat-link" data-gac="Main_menu_parts_standard" data-ga-action="15187" data-ga-label="categories" data-category-id="15187" data-parent-id="10338" data-part-type="PKW">
                        <img alt="Tirette à câble, boîte de vitesse manuelle" src="./pathback/15187.png" class="mCS_img_loaded">                                <span>Tirette à câble, boîte de vitesse manuelle</span>
                    </a>
                </li>
                                        <li class="menu-category__second-item">
                    <a href="text/valve-de-commande-transmission-automatique-15185" class="ga-click js--header__cat-link" data-gac="Main_menu_parts_standard" data-ga-action="15185" data-ga-label="categories" data-category-id="15185" data-parent-id="10338" data-part-type="PKW">
                        <img alt="Valve de commande, transmission automatique" src="./pathback/15185.png" class="mCS_img_loaded">                                <span>Valve de commande, transmission automatique</span>
                    </a>
                </li>

I want as result to have name image + text content between span tag something like this :

15187.png+Tirette à câble, boîte de vitesse manuelle

thank you

  • HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. A regex for such job will be terrible. – Toto Nov 22 '18 at 15:46
0

You really should write a script that have html parser (like php).

But if you want to do that with Notepad++, here is a way to go:

  • Ctrl+H
  • Find what: <img .*?src="[^"]+/([^/"]+).+?<span>([^<]+)</span>
  • Replace with: $1 $2
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

<img            # literally <img and a space
.*?             # 0 or more any character but newline, not greedy
src="[^"]+/     # literally src=" followed by 1 or more non quote then a slash
([^/"]+)        # group 1, 1 or more not quote not slash
.+?             # 1 or more any character but newline, not greedy
<span>          # literally <span>
([^<]+)         # group 2, 1 or more any character that is not <
</span>         # literally </span>

Replacement:

$1  # content of group 1, filename
    # a space
$2  # content of group 2, test inside span

Result for given example:

       <a href="text/tirette-a-cable-boite-de-vitesse-manuelle-15187" class="ga-click js--header__cat-link" data-gac="Main_menu_parts_standard" data-ga-action="15187" data-ga-label="categories" data-category-id="15187" data-parent-id="10338" data-part-type="PKW">
                    15187.png Tirette à câble, boîte de vitesse manuelle
                </a>
            </li>
                                    <li class="menu-category__second-item">
                <a href="text/valve-de-commande-transmission-automatique-15185" class="ga-click js--header__cat-link" data-gac="Main_menu_parts_standard" data-ga-action="15185" data-ga-label="categories" data-category-id="15185" data-parent-id="10338" data-part-type="PKW">
                    15185.png Valve de commande, transmission automatique
                </a>
            </li>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.