Welgriv
Welgriv

Reputation: 823

match symbols + and * in a regular expression using replace-regexp in emacs

Seems like a very basic question but how to catch the characters * and / or + in a regular expression using replace-regexp (or re-bulding) ? Problem is, if I am not mistaken, that + and * are used respectively to match at least one or zero or more of the previous character.

To be more specific, I would like to match something like [^*+] i.e any character other than * and +.

I can find the answer anywhere...

Upvotes: 1

Views: 62

Answers (1)

Alex Ott
Alex Ott

Reputation: 87174

If you use these characters inside square brackets, then they are treated as characters, not the repeaters. The only special care should be taken about - character - because it's used to specify ranges of characters, it should be first one if it's used in the range search, like, [-+], or [^-+].

if you're using these characters outside of the range operator, you will need to escape it with backslash, like, \+, or \\+ if it's in the code that execute regular expression.

More information about regular expression syntax you can find on EmacsWiki, and in documentation.

Upvotes: 2

Related Questions