Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Notepad++'s manual is rather vague on the special character for numerical used in extended search mode. It says: \d### - Decimal value (between 000 and 255) but literally entering "\d###" doesn't match anything.

What I am trying to do is to replace

if VarA == 12
  VarB = 1

with

if VarA == 12
  Var12=1
  VarB=1
share|improve this question

4 Answers 4

I was just looking for an answer to this question. After taking a look on the NP++ wiki, I don't think \d is matching what we want it to match.

\d
the decimal representation of a byte, made of 3 digits in the 0-9 range

It's not matching a regular numeric character, it's matching a byte code. Follow the \d with a 3-digit number and it will match the corresponding ASCII character.

In other words, \d032 matches the space character, \d033 matches an exclamation mark and so on. See here for a list of codes.

Unfortunately, this means you can't just match "any digit" using the extended options, you'll have to use the regular expressions and find a way around the new line issue.

share|improve this answer
    
You should be able to use \r\n for the new line or \n (dependent on your OS.) –  Blackbeagle Mar 25 '10 at 4:02
    
@Blackbeagle: No you can't, that's exactly the reason for this question. NP++ doesn't match new lines in the regular expression mode, but it has an interim mode that matches special characters like \n, but you can't use eg [0-9] on that. –  DisgruntledGoat Apr 5 '10 at 11:37

I was having exactly the same problem! I found a workaround. First, use the 'Extended' search mode (what you call the 'interim mode') to find and replace all the newline characters with some random character that's not in the text. For example, I replaced all my newline characters with a tilde ('~'). Then, switch to 'Regular expression' search mode, and now you can search for newlines by referring to them by your replaced character. Once you're done manipulating the text with find and replace, switch the random character back to newlines. That's it!

share|improve this answer

Trying to clarify: As I understand your code what you are trying to do is to search for:

if VarA ==

and then store the numeric value and then replace it with

if VarA == Var=1.

The problem isn't the searching, it is that you are trying to store the value. I don't know if the search/replace function can do such a thing.

share|improve this answer
if VarA == 12  
    VarB = 1

if VarA == 16  
    VarB = 0

Using Find/Replace with Regular expression

Find what: if VarA == ([0-9]+)
Replace with: if VarA == \1 \n\t Var\1=1

Run "Replace All"

Result:

if VarA == 12  
     Var12=1  
    VarB = 1

if VarA == 16  
     Var16=1  
    VarB = 0 

Is this what you were looking for?

share|improve this answer
1  
While this works now, bear in mind that the original question was asked before Notepad++ improved its regular expression engine. –  Dane Aug 26 '13 at 13:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.