Ubuntu – Questions about using Regex Search & Replace in gedit

geditpythonregex

I am trying to use the Regex Search & Replace plugin of gedit.

  1. I want to search for a digit that
    repeats 2 or 3 times, so I thought
    the regex was

    [0-9]\{2,3\}
    

    But it doesn't match the targets it
    should, such as "22".

  2. I want to find a word "Notes"
    exactly, so I thought it would be

    \<Notes\> 
    

    But it doesn't work either.

  3. How to add a "#" in front of a
    string of any three digits
    "[0-9][0-9][0-9]"? e.g. "123" becomes "#123".

I was wondering if I made some mistake? I am using Basic Regex. What type of Regex is used in the plugin? How can I learn how to use this plugin?

Best Answer

You should not need to escape your regex characters. Your first example should be:

[0-9]{2,3}

Your second example should be:

\bNote\b

For the third situation, you'll need to match things before and after, then use back-references:

(.*)([0-9]{3}.*)

with the replacement being:

\1p\2

For more details, see pydoc re that will tell you about Python regular expression syntax, or the online documentation.

Related Question