Questions about using Regex Search & Replace in gedit

21,899

Solution 1

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.

Solution 2

As Kees says, the plugin uses Python's re module syntax, which also has a How-To on the python site.

I also recommend installing and playing around with kodos Install kodos .
It's a python regular expression tester (it calls itself a 'debugger'), and includes a quick reference regex sheet as well as a shorter version of the re module documentation.

The regular-expression.info site has a nice comparison of different implementations of regular expression meta-languages. There's a decent section on the python flavor there as well.

Share:
21,899
Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on September 17, 2022

Comments

  • Tim
    Tim over 1 year

    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?

  • Tim
    Tim about 13 years
    @igbelacqua: Thanks! I guess Kodos is for KDE. If I am correct, it can be installed on Gnome but not the best if there is some other native software for Gnome. Do you know what the natives are?
  • belacqua
    belacqua about 13 years
    Hmm -- Kodos does have Qt dependencies, but it's not a KDE app per se that I can see. I run basic Ubuntu (Gnome), and it hasn't been out of place . Another option is kiki -- it's a python-wxgtk2.6 application -- not as full-featured. I used it before finding kodos. Another tester option that doesn't require an install is pythonregex.com -- it says it was inspired by Kodos, and it's clean and useful. It's possibly the easiest to use of the three.