Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ regex to find 3 consecutive numbers

Tags:

I'm trying to use Notepadd++ to find all occurrences of width=xxx so I can change them to width="xxx"

as far as I have got is width=[^\n] which only selects width=x

like image 620
atwellpub Avatar asked Apr 22 '10 15:04

atwellpub


People also ask

Can I use regex in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

Can you use regex with numbers?

The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.

How do I match a number in regex?

To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.


1 Answers

If you need exactly 3 numbers, the following is tested in Notepad++:

width=\d\d\d[^\d] 

Reading further into your requirement, you can use the tagging feature:

Find what:    width=(\d\d\d)([^\d]) Replace with: width="\1"\2 

Here, the (n) bracketed portions of the regex are stored (in sequence) as \1,\2,...\n which can be referred to in the replacement field.

As a regex engine, Notepad++ is poor. Here is a description of what's supported. Pretty basic.

like image 162
spender Avatar answered Sep 20 '22 06:09

spender