The search query is : ([\s]*print)[^(](.*)
It matches, BUT when I put ^ and $ like this : ^([\s]*print)[^(](.*)$, it doesn't.
Again both work in search-forward-regex but the 2nd one does not work in replace-regex. I was curious about this behavior
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityThe search query is : ([\s]*print)[^(](.*)
It matches, BUT when I put ^ and $ like this : ^([\s]*print)[^(](.*)$, it doesn't.
Again both work in search-forward-regex but the 2nd one does not work in replace-regex. I was curious about this behavior
What do you mean by [\s]*
? If you want to match zero or more whitespace in Emacs, use
\s-*
as documented in Backslash in Regular Expressions.
For example, the regex
^\(\s-*print\)[^(]\(.*\)$
matches
printf(blah)
^(
so that's one problem/misunderstanding, and why I said you needed to provide this information.([\s]print)
matches the text(\print)
and(sprint)
, and I'm not sure that's your intent. (n.b. I'm assuming you're callingsearch-forward-regexp
interactively).