help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regexp issue


From: Tim X
Subject: Re: Regexp issue
Date: Sun, 21 Jun 2009 11:14:57 +1000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (gnu/linux)

Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 20.06.2009 um 14:47 schrieb Alan Mackenzie:
>
>> But even that will "fail" if point is at "=" in "<=>", for some
>> reasonable value of "fail".
>
>
> When point is in the middle of the string to be found it has always to
> fail, because the search goes forward from point and never looks  back and
> therefore it oversees the start of the string to be found.
>
> --

Given the specs provided by the OP, I think both regexp are
correct. To avoid more confusion, we need to be careful not to make too
many assumptions. For example, we are asuming the regexp is to be used
with search forward in a buffer, a reasonable assumption. It is also
possible the regexp is to be used on a string or in a reverse search or
....

What I liked about Alan's first example was that he attempted to find an
anchor for the string. This is important in regexp as without any
anchors, a regexp can become extremely inefficient due to backtracking.

For the OP, if you want something more specific, we will need more
details on the way the regexp is to be used and the format of the data
being processed. The main point in the examples given is that you can
exclude something from a match by using a negated set/range using the []
syntax with the first character being the ^.  i.e. [^=]. If the pattern
to match has other specific characteristics, such as only occuring at
the beginning of the line, then Alan's example anchoring the match at
the start of the line works well, if it has to match at the end, then
using the $ will work. Perhaps it just has to be => with whitespace on each
side, in which case you could do "\s=>\s" etc.

My recommendation would be to open the data file and use re-builder and
experiment until you get the result you want 

,----[ C-h f re-builder RET ]
| re-builder is an interactive autoloaded Lisp function in `re-builder.el'.
| 
| (re-builder)
| 
| Construct a regexp interactively.
`----



-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]