Search code examples
phpregexnotepad++spacemailto

in mailto: replace subject and body adding %20 instead space in all file php using notepad++


Goodmorning, I have a question... I have a blog with mailto in each post/comment that contains subject and body but between the words there are blank space that I'd like replace with %20 for better validation html. Each mailto has a different subject and body and I'd like to replace using notepad++ regex matching only this kind of string:

<A HREF="mailto:[email protected]?subject=Diario: Tanto per ridere un p&ograve;...&amp;body=Gentile visitatore, La informo che messaggi offensivi o volgari verranno scartati, buona prosecuzione." CLASS="hyperlink">Pippo Pluto</A>

<A HREF="mailto:[email protected]?subject=Diario: Dead Space e Dead Sapce 2&amp;body=Gentile visitatore, La informo che messaggi offensivi o volgari verranno scartati, buona prosecuzione." CLASS="hyperlink">Paolino Paperino</A>

As result I'd like to have:

<A HREF="mailto:[email protected]?subject=Diario:%20Neutrini%20sfondano%20i%20300.000%20Km/s&amp;body=Gentile%20visitatore,%20La%20informo%20che%20messaggi%20offensivi%20o%20volgari%20verranno%20scartati,%20buona%20prosecuzione." CLASS="hyperlink">De Paperis Pico</A>

I have 560 php files that contain the blank space and I'd like to process all files using a regular expression in Notepad++

I wrote this regex that finds only the mailto string, but does not cover the occurrence of blank space.

<A HREF=\"mailto:([^"]*)\" CLASS="hyperlink">

Is there a solution?


Solution

  • I tweaked your Regex expression to include two more groups and create a Find String like this

    <A HREF=\"mailto:([^"]*)(\s)(.*)\" CLASS="hyperlink">
    

    and the Replace string should be like this

    <A HREF=\"mailto:\1%20\3\" CLASS="hyperlink">
    

    My idea is to capture one occurance of a whitespace and replacing it with %20. However When you apply Replace All inside notepad++(regular expression mode), it will replace only one space on all matching lines so you have to click on Replace All several times until the message says 0 occurance was replaced.