unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* regexp-builder shows matches, re-search-forward fails?
@ 2012-07-26 10:51 Thorsten Jolitz
  2012-07-26 10:54 ` Jambunathan K
  2012-07-26 11:17 ` Tassilo Horn
  0 siblings, 2 replies; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 10:51 UTC (permalink / raw)
  To: help-gnu-emacs


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? 

-- 
cheers,
Thorsten





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 10:51 regexp-builder shows matches, re-search-forward fails? Thorsten Jolitz
@ 2012-07-26 10:54 ` Jambunathan K
  2012-07-26 11:15   ` Thorsten Jolitz
  2012-07-26 11:17 ` Tassilo Horn
  1 sibling, 1 reply; 12+ messages in thread
From: Jambunathan K @ 2012-07-26 10:54 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: help-gnu-emacs

Thorsten Jolitz <tjolitz@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?

-- 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 10:54 ` Jambunathan K
@ 2012-07-26 11:15   ` Thorsten Jolitz
  2012-07-26 11:23     ` Thorsten Jolitz
  2012-07-26 11:25     ` Jambunathan K
  0 siblings, 2 replies; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 11:15 UTC (permalink / raw)
  To: help-gnu-emacs

Jambunathan K <kjambunathan@gmail.com> writes:

> Check you `point'.  Is it already past the matches?

No, I use (goto-char (point-min)) before the re-search-forward. And I
print out the (current-buffer in the function - its the right one). 

BTW its a temp buffer - but that shouldn't matter, right? 

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 10:51 regexp-builder shows matches, re-search-forward fails? Thorsten Jolitz
  2012-07-26 10:54 ` Jambunathan K
@ 2012-07-26 11:17 ` Tassilo Horn
  2012-07-26 11:29   ` Thorsten Jolitz
  1 sibling, 1 reply; 12+ messages in thread
From: Tassilo Horn @ 2012-07-26 11:17 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@googlemail.com> writes:

Hi Thorsten,

> 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.

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:15   ` Thorsten Jolitz
@ 2012-07-26 11:23     ` Thorsten Jolitz
  2012-07-26 13:29       ` Tassilo Horn
  2012-07-26 11:25     ` Jambunathan K
  1 sibling, 1 reply; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 11:23 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@googlemail.com> writes:

> Jambunathan K <kjambunathan@gmail.com> writes:
>
>> Check you `point'.  Is it already past the matches?
>
> No, I use (goto-char (point-min)) before the re-search-forward. And I
> print out the (current-buffer in the function - its the right one). 
>
> BTW its a temp buffer - but that shouldn't matter, right? 

More concrete:

,-------------------------
| \\(^# Task: \\)\\(.*$\\)
`-------------------------

does match both tasks in 

,----------------------
| # Task: A+B
| 
| (+ (read) (read))
| 3 4
| -> 7
| 
| 
| # Task: Abstract type
`----------------------

in regexp-builder, but 

,------------------------------------------------
| (re-search-forward  "\\(^# Task: \\)\\(.*$\\)")
`------------------------------------------------

with point at beginning of that buffer gives 'search-failed'. 

Thats strange.
(I tried \( and \\\\( for escaping too, but to no avail)

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:15   ` Thorsten Jolitz
  2012-07-26 11:23     ` Thorsten Jolitz
@ 2012-07-26 11:25     ` Jambunathan K
  2012-07-26 11:35       ` Thorsten Jolitz
  1 sibling, 1 reply; 12+ messages in thread
From: Jambunathan K @ 2012-07-26 11:25 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: help-gnu-emacs

Thorsten Jolitz <tjolitz@googlemail.com> writes:

> Jambunathan K <kjambunathan@gmail.com> writes:
>
>> Check you `point'.  Is it already past the matches?
>
> No, I use (goto-char (point-min)) before the re-search-forward. And I
> print out the (current-buffer in the function - its the right one). 
>
> BTW its a temp buffer - but that shouldn't matter, right? 

What is your value of `reb-re-syntax'.  Is it in read format?

-- 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:17 ` Tassilo Horn
@ 2012-07-26 11:29   ` Thorsten Jolitz
  2012-07-26 13:24     ` Tassilo Horn
  0 siblings, 1 reply; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 11:29 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> writes:

> Thorsten Jolitz <tjolitz@googlemail.com> writes:
>
Hi Tassilo,

>> 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. 

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:25     ` Jambunathan K
@ 2012-07-26 11:35       ` Thorsten Jolitz
  2012-07-26 11:36         ` Eric Abrahamsen
  0 siblings, 1 reply; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 11:35 UTC (permalink / raw)
  To: help-gnu-emacs

Jambunathan K <kjambunathan@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. 

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:35       ` Thorsten Jolitz
@ 2012-07-26 11:36         ` Eric Abrahamsen
  0 siblings, 0 replies; 12+ messages in thread
From: Eric Abrahamsen @ 2012-07-26 11:36 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Jul 26 2012, Thorsten Jolitz wrote:

> Jambunathan K <kjambunathan@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




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:29   ` Thorsten Jolitz
@ 2012-07-26 13:24     ` Tassilo Horn
  0 siblings, 0 replies; 12+ messages in thread
From: Tassilo Horn @ 2012-07-26 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@googlemail.com> writes:

>> What's reb-copy?
>
> 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.

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 11:23     ` Thorsten Jolitz
@ 2012-07-26 13:29       ` Tassilo Horn
  2012-07-26 15:51         ` Thorsten Jolitz
  0 siblings, 1 reply; 12+ messages in thread
From: Tassilo Horn @ 2012-07-26 13:29 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@googlemail.com> writes:

Hi Thorsten,

> More concrete:
>
> ,-------------------------
> | \\(^# Task: \\)\\(.*$\\)
> `-------------------------
>
> does match both tasks in 
>
> ,----------------------
> | # Task: A+B
> | 
> | (+ (read) (read))
> | 3 4
> | -> 7
> | 
> | 
> | # Task: Abstract type
> `----------------------
>
> in regexp-builder,

Ditto here.

> but
>
> ,------------------------------------------------
> | (re-search-forward  "\\(^# Task: \\)\\(.*$\\)")
> `------------------------------------------------
>
> 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?

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: regexp-builder shows matches, re-search-forward fails?
  2012-07-26 13:29       ` Tassilo Horn
@ 2012-07-26 15:51         ` Thorsten Jolitz
  0 siblings, 0 replies; 12+ messages in thread
From: Thorsten Jolitz @ 2012-07-26 15:51 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> writes:

Hi Tassilo,

> 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. 

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-07-26 15:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 10:51 regexp-builder shows matches, re-search-forward fails? Thorsten Jolitz
2012-07-26 10:54 ` Jambunathan K
2012-07-26 11:15   ` Thorsten Jolitz
2012-07-26 11:23     ` Thorsten Jolitz
2012-07-26 13:29       ` Tassilo Horn
2012-07-26 15:51         ` Thorsten Jolitz
2012-07-26 11:25     ` Jambunathan K
2012-07-26 11:35       ` Thorsten Jolitz
2012-07-26 11:36         ` Eric Abrahamsen
2012-07-26 11:17 ` Tassilo Horn
2012-07-26 11:29   ` Thorsten Jolitz
2012-07-26 13:24     ` Tassilo Horn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).