* Regexp issue
@ 2009-06-20 8:39 Paulo J. Matos
2009-06-20 8:53 ` Peter Dyballa
[not found] ` <mailman.985.1245488055.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Paulo J. Matos @ 2009-06-20 8:39 UTC (permalink / raw
To: help-gnu-emacs
Hi all,
How can I match the string => but not part of <=>?
Cheers,
Paulo Matos
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
[not found] <mailman.984.1245487162.2239.help-gnu-emacs@gnu.org>
@ 2009-06-20 8:46 ` Marc Tfardy
0 siblings, 0 replies; 8+ messages in thread
From: Marc Tfardy @ 2009-06-20 8:46 UTC (permalink / raw
To: help-gnu-emacs
Paulo J. Matos schrieb:
> Hi all,
>
> How can I match the string => but not part of <=>?
This would be works, but is probably not what you are looking for:
[^<]=>
regards
Marc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
2009-06-20 8:39 Regexp issue Paulo J. Matos
@ 2009-06-20 8:53 ` Peter Dyballa
[not found] ` <mailman.985.1245488055.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: Peter Dyballa @ 2009-06-20 8:53 UTC (permalink / raw
To: Paulo J. Matos; +Cc: help-gnu-emacs
Am 20.06.2009 um 10:39 schrieb Paulo J. Matos:
> How can I match the string => but not part of <=>?
[^<]=>
[everything but "<"]<followed by exactly "=>">
--
Greetings
Pete
When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
– Rinzai, ninth century Zen master
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
[not found] ` <mailman.985.1245488055.2239.help-gnu-emacs@gnu.org>
@ 2009-06-20 10:17 ` Alan Mackenzie
2009-06-20 11:16 ` Peter Dyballa
[not found] ` <mailman.993.1245496611.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Alan Mackenzie @ 2009-06-20 10:17 UTC (permalink / raw
To: help-gnu-emacs
Peter Dyballa <Peter_Dyballa@web.de> wrote:
> Am 20.06.2009 um 10:39 schrieb Paulo J. Matos:
>> How can I match the string => but not part of <=>?
> [^<]=>
> [everything but "<"]<followed by exactly "=>">
Or, more precisely,
\(^\|[^<]\)=>
, i.e. [nothing at all] or [something which isn't "<"] following by =>.
If you're using this in a string in a lisp program, you'll have to double
up the backquotes, something like
(search-forward-regexp "\\(^\\|[^<]\\)=>")
> --
> Greetings
> Pete
--
Alan Mackenzie (Nuernberg).
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
2009-06-20 10:17 ` Alan Mackenzie
@ 2009-06-20 11:16 ` Peter Dyballa
[not found] ` <mailman.993.1245496611.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: Peter Dyballa @ 2009-06-20 11:16 UTC (permalink / raw
To: Alan Mackenzie; +Cc: help-gnu-emacs
Am 20.06.2009 um 12:17 schrieb Alan Mackenzie:
> Or, more precisely,
>
> \(^\|[^<]\)=>
The imprecise form works for me in GNU Emacsen 22.3 and 23.0.94 (to
find => at the beginning of a line) ...
--
Greetings
Pete
I love deadlines. I love the whooshing noise they make as they go by.
– Douglas Adams
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
[not found] ` <mailman.993.1245496611.2239.help-gnu-emacs@gnu.org>
@ 2009-06-20 12:47 ` Alan Mackenzie
2009-06-20 14:53 ` Peter Dyballa
[not found] ` <mailman.996.1245509629.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Alan Mackenzie @ 2009-06-20 12:47 UTC (permalink / raw
To: help-gnu-emacs
Peter Dyballa <Peter_Dyballa@web.de> wrote:
> Am 20.06.2009 um 12:17 schrieb Alan Mackenzie:
>> Or, more precisely,
>> \(^\|[^<]\)=>
> The imprecise form works for me in GNU Emacsen 22.3 and 23.0.94 (to
> find => at the beginning of a line) ...
Only at the beginning of _some_ lines. ;-)
Actually, come to think of it, both of our regexps are wrong. Neither
of them will find "=>" at point in the middle of a line. Better would
be
\(\=\|[^<]\)=>
. But even that will "fail" if point is at "=" in "<=>", for some
reasonable value of "fail". By now, the OP is probably wishing he hadn't
bothered asking this question. ;-)
> Pete
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
2009-06-20 12:47 ` Alan Mackenzie
@ 2009-06-20 14:53 ` Peter Dyballa
[not found] ` <mailman.996.1245509629.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: Peter Dyballa @ 2009-06-20 14:53 UTC (permalink / raw
To: Alan Mackenzie; +Cc: help-gnu-emacs
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.
--
Mit friedvollen Grüßen
Pete
One cannot live by television, video games, top ten CDs, and dumb
movies alone.
– Amiri Baraka, 1999
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regexp issue
[not found] ` <mailman.996.1245509629.2239.help-gnu-emacs@gnu.org>
@ 2009-06-21 1:14 ` Tim X
0 siblings, 0 replies; 8+ messages in thread
From: Tim X @ 2009-06-21 1:14 UTC (permalink / raw
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-06-21 1:14 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-20 8:39 Regexp issue Paulo J. Matos
2009-06-20 8:53 ` Peter Dyballa
[not found] ` <mailman.985.1245488055.2239.help-gnu-emacs@gnu.org>
2009-06-20 10:17 ` Alan Mackenzie
2009-06-20 11:16 ` Peter Dyballa
[not found] ` <mailman.993.1245496611.2239.help-gnu-emacs@gnu.org>
2009-06-20 12:47 ` Alan Mackenzie
2009-06-20 14:53 ` Peter Dyballa
[not found] ` <mailman.996.1245509629.2239.help-gnu-emacs@gnu.org>
2009-06-21 1:14 ` Tim X
[not found] <mailman.984.1245487162.2239.help-gnu-emacs@gnu.org>
2009-06-20 8:46 ` Marc Tfardy
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.