Remove "minus" only in selected Lines

Storm
2014-03-19
2014-03-22
  • Storm
    Storm
    2014-03-19

    Hi there,I want to clean telefone numbers in vcard. Atm the nummbers look like this 123-54-789-00 and I want them to look like this 12345678900.
    So I want to delete the "-" only in lines that include the string "TEL;TYPE=". But a full line looks like this: TEL;TYPE=WORK:123-54-789-00
    So the operation has to look for the string with the TEL but ignore anything behind the "=".
    I can't simply remove all "-" because some are in email adresses or streetnames.
    Is there a way to do this?

    Thx 4 F1
    st.

     
  • THEVENOT Guy
    THEVENOT Guy
    2014-03-20

    Hello Storm,

    Well, I think we can achieve it with two consecutive Search/Replacements !

    We'll need an extra character which DOESN'T exist in your file. Let suppose it's the # character ( You may choose the @, _ or ; character, as well. However, try to avoid characters that have special meaning in regexes, like, for example, ? or [. !

    For each S/R :

    • Move back, if necessary, to the beginning of your file ( CTRL + Org )

    • Open the Replace dialog ( CTRL + H )

    • Fill in the two zones Find what: and Replace with : with the strings below

    • Select the Regular expression search mode

    • DON'T check any other square box option

    • Click on the Replace All button, at the right side

    A) First regex :

    SEARCH : .*TEL;TYPE=.*

    REPLACE : $0#

    B) Second regex :

    SEARCH : -(?=.*#)|#

    REPLACE : Nothing

    NOTES :

    • In the first S/R, we're looking for the totality of all the lines, containing the string TEL;TYPE=. And we replace with the entire search string ($0), followed by our dummy character ( # )

    => So, the adding # character is used to mark all lines with a phone number :-)

    • In this first S/R, the form .* represents any string, even a zero length string, before and after the string TEL;TYPE=

    • In the second S/R, we're searching for a dash ( - ) ONLY IF it's followed further, on the same line, with the # character OR the # character. And we just replace it by Nothing, as it must be deleted

    • In this second S/R, the form (?=.*#) is called a lookahead, which must be verified, but which is NOT part of the final regex, the dash ( - ) to match.

    • In the second S/R, after the last dash, of each line, is deleted, the # character is matched by the second part of the alternative and is ALSO deleted !


    You will find good documentation, about the new PERL Common Regular Expressions (PCRE), used by N++, since the 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    The FIRST link concerns the syntax of regular expressions in SEARCH

    The SECOND link concerns the syntax of regular expressions in REPLACEMENT

    Cheers,

    guy038

    P.S. :

    Oh, BTW, I do like your shortcut : Thx 4 F1 for Thanks for (your) help !!!

     
    Last edit: THEVENOT Guy 2014-03-20
  • Storm
    Storm
    2014-03-22

    @ THEVENOT Guy:
    It totally worked. You knew that, right? ;)
    Awesome. Thank you very much.

    Concerning the shortcut: I'm using it for at least 10 years now. Nobody ever paid attention. I have never ever seen it anywhere else. Feel free to use it. I'm happy you like it :)

    Thx 4 F1!!! ;) :D

    st.

     
    Last edit: Storm 2014-03-22