louis, (edited )
@louis@emacs.ch avatar

Not sure what I'm doing wrong, but I'm trying to do some project-find-regexp with an expression like this: func() and it still finds everything with func. I was expecting that it only finds "func()", what did I get wrong?

graywolf, (edited )
@graywolf@emacs.ch avatar

@louis I think func() is evaluated as func' followed by empty capture group. I tried C-x p g for just func()' and it seems to do what you want.

EDIT: https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html seems relevant.

RogerBW, (edited )
@RogerBW@emacs.ch avatar

@louis I don't know this specific context but I've worked with regexp libraries that took () as literal and () as grouping operators (e.g. in sed and nvi).

rahguzar,
@rahguzar@emacs.ch avatar

@RogerBW @louis this seems to be case in My way of dealing with regexes in Elisp is to use rx and (rx "func()") outputs "func()".

ramin_hal9001, (edited )
@ramin_hal9001@emacs.ch avatar

> "I've worked with regexp libraries that took () as literal and () as grouping operators (e.g. in sed and nvi)"

@RogerBW @louis this is the correct answer in the case of Emacs. Here "(...)" are grouping operators, do not use backslashes if you want to match literal paren characters. Another good way to ensure you mean literal parens is to write "[(][)]", i.e. place them in character sets.

Confusingly, Emacs treats "+" as "match one or more" and "+" a literal character, which is the opposite of how Sed and "grep -e" does it. Apart from that, the escape codes in Emacs work pretty much the same as Sed or "grep -e".

  • All
  • Subscribed
  • Moderated
  • Favorites
  • emacs
  • DreamBathrooms
  • mdbf
  • ngwrru68w68
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • osvaldo12
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • InstantRegret
  • tacticalgear
  • anitta
  • ethstaker
  • provamag3
  • cisconetworking
  • tester
  • GTA5RPClips
  • cubers
  • everett
  • modclub
  • megavids
  • normalnudes
  • Leos
  • JUstTest
  • lostlight
  • All magazines