I constructed a regexp with regexp-builder for a buffer, the matches are
clearly shown, with all the subexpressions in different colors. Then I
do reb-copy and paste the regexp as argument for a re-search-forward
call. In the same buffer I used to build the regexp, re-search-forward
now fails to match anything.
Thorsten Jolitz <tjol...@googlemail.com> writes:
> Hi List,
> I constructed a regexp with regexp-builder for a buffer, the matches are
> clearly shown, with all the subexpressions in different colors. Then I
> do reb-copy and paste the regexp as argument for a re-search-forward
> call. In the same buffer I used to build the regexp, re-search-forward
> now fails to match anything.
> What might be the reason?
Check you `point'. Is it already past the matches?
> I constructed a regexp with regexp-builder for a buffer, the matches
> are clearly shown, with all the subexpressions in different colors.
> Then I do reb-copy and paste the regexp as argument for a
> re-search-forward call. In the same buffer I used to build the
> regexp, re-search-forward now fails to match anything.
> What might be the reason?
What's reb-copy?
The problem might be that re-builder wants the regex as string, so you
have to quote backslashes. E.g., re-builder wants "\\(foo\\|bar\\)",
but at the re-search-forward prompt you have to say just \(foo\|bar\)
and emacs does the quoting for you.
>> I constructed a regexp with regexp-builder for a buffer, the matches
>> are clearly shown, with all the subexpressions in different colors.
>> Then I do reb-copy and paste the regexp as argument for a
>> re-search-forward call. In the same buffer I used to build the
>> regexp, re-search-forward now fails to match anything.
>> What might be the reason?
> What's reb-copy?
it copies the regexp from regexp-builder for use in an elisp function,
thats what I need.
> The problem might be that re-builder wants the regex as string, so you
> have to quote backslashes. E.g., re-builder wants "\\(foo\\|bar\\)",
> but at the re-search-forward prompt you have to say just \(foo\|bar\)
> and emacs does the quoting for you.
Thats true, when I use \(foo\|bar\) in M-x re-search-forward it matches
again. But in my function, neither \( nor \\( nor \\\\( work. Maybe
something else wrong with with function - have to check again. Thanks.
Jambunathan K <kjambunat...@gmail.com> writes:
> What is your value of `reb-re-syntax'. Is it in read format?
yes.
But I think I got confused, because I used re-search-forward in a while
loop and tried to replace the matches, but the REPLACEMENT didn't work,
the search did - the message "search-failed" was only from the last
iteration in the while loop when no matches were left.
Ok, I got it - thanks for the help and sorry for the noise.
On Thu, Jul 26 2012, Thorsten Jolitz wrote:
> Jambunathan K <kjambunat...@gmail.com> writes:
>> What is your value of `reb-re-syntax'. Is it in read format?
> yes.
> But I think I got confused, because I used re-search-forward in a while
> loop and tried to replace the matches, but the REPLACEMENT didn't work,
> the search did - the message "search-failed" was only from the last
> iteration in the while loop when no matches were left.
Just a note, the second optional argument to re-search-forward is
NOERROR: set to 't', it will allow the search to halt quietly. I kind of
wish that was the default.
-- GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.11)
of 2012-07-23 on pellet
> it copies the regexp from regexp-builder for use in an elisp function,
> thats what I need.
Ah, I didn't know that. And you are using re-search-forward in a
program, not interactively. Well, in that case, the regex syntax are
identically, i.e., you can kill the "<regex>" from the re-builder prompt
and yank it into (re-search-forward "<regex>" nil t) and it should just
work.
> with point at beginning of that buffer gives 'search-failed'.
Not for me. I can call exactly that twice and point moves to the end of
the # Task items as it should. The third call then signal no match,
cause there are no more matches.
I used M-: to test that. Maybe you're running the search on the wrong
buffer?
> Not for me. I can call exactly that twice and point moves to the end of
> the # Task items as it should. The third call then signal no match,
> cause there are no more matches.
I figured that out, the search was actually ok, but I made a mistake in
the replacement. Since the whole thing was in a while loop, all
appereances were found, but nothing happened (buggy replacement) and the
last loop gave the error message 'search-failed', so all I saw was that
nothing happened - and that error message, confusing me about the cause
of the error.