How to search for a string and replace with blank



  • <Setting name="+$files#0" value=FILES\CONTENT.IE5\INDEX.DAT"/>
    <Setting name="+$files#1" value=C:\PROGRAM FILES

    I want to replace <Setting name="+$files#1" value= with blank but the number changes from 0 to 1, 2 and so on. I tried to replace the number with a question mark and didn’t work <Setting name="+$files#?" value=



  • Hello, @cesar-silva,

    Not really difficult with regular expressions, indeed !

    • Move back to the very beginning of your file

    • Open the Replace dialog ( Ctrl + H )

    • Type, in the Find what: zone, the regex (?-i)<Setting name="\+\$files#\d+" value=

    • Let the Replace with: zone EMPTY , if your want to delete the searched string OR insert a space character ( or \x20 ) if you prefer to replace the searched string with a blank character

    • Let all the options unticked

    • Select the Regular expression search mode

    • Click on the Replace All button

    Done !

    Notes :

    • The (?-i) modifier forces the search to be NON-insensitive. If you prefer an insensitive search, use the (?i) modifier.( Note that if you omit the modifier part, you’ll have to, manually, check/uncheck the Match case option )

    • Then it searches for the literal string <Setting name="+$files#. Note that the special characters + and $ have to be escaped, with a backslash ( \ ) => the part <Setting name="\+\$files#

    • Now, the part \d+ matches any positive integer number, with any digit(s), as 0, 12, 19037,…

    • Finally, it looks for the literal string " value=

    Best Regards,

    guy038



  • Thank you very much. It worked :)

    I appreciated :)



  • @guy038 said:

    NON-insensitive

    guy038, thanks for the detailed explanation. But this whole thing about search type switches: i.e. “Intensive” and “NON-Intensive” have left my head spinning. heh.

    I have a sting in a SQL script: “-- bla, bla, bla, bla” (less the quotes) and want to search something like this: ** “-- *” **(once again without the quotes) the same way I do in Windows Notepad. How can I do this?

    Thanks in advance for any help you can offer.

    Regards,
    Q



  • @Quincy-Gouveia NON-insensitive refers to case-sensitivity, that is, whether or not the search is sensitive to capital letters being different from lower-case letters. For example, searching for bla in a case-insensitive search would ignore the case of the letters and could match Bla, BLA, or bla, but searching for bla in a case-sensitive (= NON-insensitive) search would only match bla. This is the same as checking (sensitive) or unchecking (insensitive) the Match case checkbox in the Find dialog box in Notepad or Notepad++. @guy038 referred to it as NON-insensitive (a double-negative) to explain the meaning of the -i (insensitive) flag.

    Simple answer:

    Type -- in the Find what: box, making sure that especially the Normal Search Mode is checked. However, this will not include any following characters in the match, which may or may not matter, depending on what you want to do after you find this text.

    Exact answer:

    I wasn’t aware Windows Notepad allowed you to use wildcards, but I assume that you’re asking about how to search in a way equivalent to using the Windows wildcards * and ?. You want to search for two hyphens --, followed by a space (), followed by 0 or more of any character, and include any characters after the space in the match, correct?

    I’m actually surprised your search did not succeed, unless perhaps you had the Normal Search Mode selected instead of Regular Expression? A regex of -- * should search for two hyphens followed by 0 or more spaces. But read on to discover the technically correct answer that actually selects the text after the hyphens + space combination.

    One good primer on Regular Expressions can be found at http://www.regular-expressions.info, but here’s a 3-point start:

    1. To search for any character, use the full stop/period . character. Equivalent to Windows wildcard ?.
    2. To search for 0 or more occurrences of a character, follow the character with an asterisk *. Windows uses the asterisk by itself to mean 0 or more occurrences of any character, but Regular Expressions uses it to act on the character before it. For example, ap* could match anchor (a plus 0 p chars following), ape (a plus 1 p char following) or apple (a plus 2 p chars following), etc.
    3. To search for 0 or more occurrences of any character on that line, use .* This is equivalent to Windows wildcard *, but requires the full stop . before it.

    Here is how you would search in Notepad++ for any line that contains two hyphens, followed by a space, and include all following text on that line in the match:

    • Move back to the very beginning of your file
    • Open the Replace dialog ( Ctrl + H )
    • Type this regex string in the box following Find what: -- .*
    • Leave all the options unticked.
    • Select the Regular expression search mode.
    • Click on the Find (or Find > >) button.

    If you want to remove, replace, or modify the SQL comment, or if you want to require that the comment start at the beginning of the line, you can do either of those and more. Please post again with more details if you need help with what you want to do next. I also would strongly recommend at least skimming a Regular Expression tutorial.


Log in to reply