25

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

6 Answers 6

36

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.

9
  • 2
    So it doesn't support {3} but it does support negating character classes (which isn't always supported?) what sort of "Regular Expressions" craziness did they put in Notepad++???
    – gnarf
    Commented Apr 22, 2010 at 16:12
  • Though it does support \d, which isn't listed on that page, so I suspect that page is inaccurate and out of date. I've used \s+ and \t.
    – jmanning2k
    Commented Apr 22, 2010 at 16:19
  • The width="\1"\2 replace leaves width="", so it looks like the \1 does not return any digits
    – atwellpub
    Commented Apr 22, 2010 at 16:19
  • sorry I didnt alter my search to width=(\d\d\d). Thank you all!
    – atwellpub
    Commented Apr 22, 2010 at 16:22
  • 3
    quick note, this limitation no longer applies - as of version 6, Notepad++ supports (uses?) PCRE - the perl-compatible regular expressions library; as far a I can tell, that quickly elevates it from one of the worst levels of regexp support to top-notch support!
    – Tao
    Commented Apr 13, 2012 at 10:34
12

Looking at the Notepad++ Regular Expression list there does not seem to support the {n} notation to match n characters, so \d{3} did not work.

However, what had worked for me and may be considered a hack was: \d\d\d

Tested in Notepad++ and has worked, for the Find field use (\d\d\d) and for the Replace filed use "\1"\2.

1
  • This was a success width=\d\d\d, but I'm at loss on what to set the replace to to preserve the 3 numbers
    – atwellpub
    Commented Apr 22, 2010 at 16:15
11

As Tao commented, as of version 6, Notepad++ supports PCRE.

So now You can write:

\d{1,5}
2
  • I tested in 6.3, it says "Incorrect regular expression"... It should be \d{1,5}
    – mrdaliri
    Commented Mar 21, 2013 at 22:04
  • Awesome! Just what I'm looking for. Use \d{10}, for example, to find a string of 10 numbers. Commented Feb 6, 2016 at 21:31
2
/(width=)(\d+?)/gim

Because you may want variable digits. Some widths may be 8, or 15, or 200, or whatever.

If you want to specify a range, you do it like this:

/(width=)(\d{1,3)/gim

where the 1 represents the lower limit and the 3 represents the upper.

I grouped both parts of the expression, so when you replace you can keep the first part and not blow it away.

2

Tried it: replace width=([0-9][0-9][0-9]) with width="\1" and worked fine... Of course might not be best syntax to do this but it works...

0

I would try this one: width=(\d{3,}), and check Regular expression, and also . matches newline

works for me on ver: 7.5.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.