unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Why are RegExps never working?
@ 2007-11-11 14:06 Sven Bretfeld
  2007-11-11 14:47 ` Peter Dyballa
  2007-11-11 15:21 ` Bastien
  0 siblings, 2 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-11 14:06 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 904 bytes --]

Hello all

I'm just a beginner in using Regexp operations. I know that Emacs
RegExps are somewhat different from those of awk etc. But I'm
using the GNU Emacs manual to look them up.

I usually need them to do some editing (isearch-forward-regexp or
query-replace-regexp) in LaTeX-files which were MS-Word files
originally. I'm using AucTeX in Emacs 22.1.50.1.

For example, I want to search every occurrence of pp. `number' (to
replace it by pp.~`number'). Instead of space, pp. can also be
followed by an end-of-line. So I think this RegExp should be correct:

pp\.[ \|$][0-9]

To my understanding, it should mean: the string pp. followed by a
group consisting of space or end-of-line followed by a number.

Alas, occurrences of pp. at the end of a line are never found. I've
also tried \n instead of $ and [ $] instead of [ \|$] -- all with the
same result.

What's my mistake?

Thanks for help

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-11 15:21 ` Bastien
@ 2007-11-11 14:38   ` Sven Bretfeld
  0 siblings, 0 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-11 14:38 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 314 bytes --]

Hi Bastien

Bastien <bzg@altern.org> writes:

> pp\.[ \n][0-9]+
>
> ?
>
> See (info "(elisp)Regular Expressions")

Thanks, I've tried that already, but it's just not working. Try it with
the following:

text pp. 44 text text text text text text text text text text pp.
54 text 

Greetings

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-11 14:06 Why are RegExps never working? Sven Bretfeld
@ 2007-11-11 14:47 ` Peter Dyballa
  2007-11-11 15:19   ` Sven Bretfeld
  2007-11-11 15:21 ` Bastien
  1 sibling, 1 reply; 28+ messages in thread
From: Peter Dyballa @ 2007-11-11 14:47 UTC (permalink / raw)
  To: Sven Bretfeld; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1103 bytes --]


Am 11.11.2007 um 15:06 schrieb Sven Bretfeld:

> pp\.[ \|$][0-9]
>
> To my understanding, it should mean: the string pp. followed by a
> group consisting of space or end-of-line followed by a number.
>
> ...
>
> What's my mistake?

You mean: what *are* ?

Everything between square brackets, i.e. in [], are alternatives, no  
| is needed.

What you are trying to search and destroy, ahhem, replace are not  
line endings but line feeds inside the from expression. These are put  
into the expression as C-q C-j. The expression between [] won't look  
like such, but I can give you some guarantee: it works! Definitely.


And please read again what a "group" in regular expressions is! The `` 
[ \|$]´´ and the ``[0-9]´´ are bracket expressions, a faulty (for  
your purpose) and a working one. If you want to re-use parts of the  
search expression you can use:

	\(pp\.\)[ ^J]\([0-9]\)  ->  \1~\2

Line feed or SPC are converted to ~.

--
Mit friedvollen Grüßen

   Pete

Well done is better than well said.
                            -- Benjamin Franklin



[-- Attachment #1.2: Signierter Teil der Nachricht --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-11 14:47 ` Peter Dyballa
@ 2007-11-11 15:19   ` Sven Bretfeld
  2007-11-11 15:52     ` Peter Dyballa
       [not found]     ` <mailman.3268.1194797266.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-11 15:19 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1170 bytes --]

Hi Peter

You're my savior again. Thanks.

Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> You mean: what *are* ?

I think it's still only one mistake.

> Everything between square brackets, i.e. in [], are alternatives, no |
> is needed.

> What you are trying to search and destroy, ahhem, replace are not line
> endings but line feeds inside the from expression. These are put  into
> the expression as C-q C-j. 

This works perfectly (of course). I will search in the info for the
difference between a line feed and an end of line, which is not clear
to me.

> The expression between [] won't look  like
> such, but I can give you some guarantee: it works! Definitely.
>
> And please read again what a "group" in regular expressions is! The ``
> [ \|$]´´ and the ``[0-9]´´ are bracket expressions, a faulty (for your
> purpose) and a working one. If you want to re-use parts of the  search
> expression you can use:
>
> 	\(pp\.\)[ ^J]\([0-9]\)  ->  \1~\2
>
> Line feed or SPC are converted to ~.

Sorry, wrong terminology. Yes, I'm usually using "groups" like that to
search and replace regexps.

Thank you very much

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-11 14:06 Why are RegExps never working? Sven Bretfeld
  2007-11-11 14:47 ` Peter Dyballa
@ 2007-11-11 15:21 ` Bastien
  2007-11-11 14:38   ` Sven Bretfeld
  1 sibling, 1 reply; 28+ messages in thread
From: Bastien @ 2007-11-11 15:21 UTC (permalink / raw)
  To: help-gnu-emacs

Sven Bretfeld <sven.bretfeld@gmx.ch> writes:

> pp\.[ \|$][0-9]
>
> To my understanding, it should mean: the string pp. followed by a
> group consisting of space or end-of-line followed by a number.
>
> Alas, occurrences of pp. at the end of a line are never found. I've
> also tried \n instead of $ and [ $] instead of [ \|$] -- all with the
> same result.

pp\.[ \n][0-9]+

?

See (info "(elisp)Regular Expressions")

-- 
Bastien

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

* Re: Why are RegExps never working?
  2007-11-11 15:19   ` Sven Bretfeld
@ 2007-11-11 15:52     ` Peter Dyballa
  2007-11-11 23:24       ` Sven Bretfeld
       [not found]       ` <mailman.3307.1194823515.18990.help-gnu-emacs@gnu.org>
       [not found]     ` <mailman.3268.1194797266.18990.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 28+ messages in thread
From: Peter Dyballa @ 2007-11-11 15:52 UTC (permalink / raw)
  To: Sven Bretfeld; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1183 bytes --]


Am 11.11.2007 um 16:19 schrieb Sven Bretfeld:

> This works perfectly (of course). I will search in the info for the
> difference between a line feed and an end of line, which is not clear
> to me.

I'm not sure whether it's described so clearly. The main thing is  
that text is line oriented and therefore $ states end of line. And  
therefore regular expressions end at line's end. So in the middle of  
the from part $ cannot have another meaning than the character $  
itself. If the from part has to stretch over more than one line, then  
each line ending has to be expressed with the linefeed character that  
separates the text into more than one line. Could be sometimes a  
carriage return (^M) has to be used, or some combination of carriage  
return and linefeed ...

--
Mit friedvollen Grüßen

   Pete

If my theory of relativity is proven successful, Germany will claim  
me as a German, and France will declare that I am a citizen of the  
world. Should my theory prove untrue, France will say that I am a  
German, and Germany will declare that I am a Jew.
                                                 -- Albert Einstein,  
1929



[-- Attachment #1.2: Signierter Teil der Nachricht --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-11 15:52     ` Peter Dyballa
@ 2007-11-11 23:24       ` Sven Bretfeld
  2007-11-12  9:39         ` Peter Dyballa
       [not found]       ` <mailman.3307.1194823515.18990.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-11 23:24 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 893 bytes --]

Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> I'm not sure whether it's described so clearly. The main thing is that
> text is line oriented and therefore $ states end of line. And
> therefore regular expressions end at line's end. So in the middle of
> the from part $ cannot have another meaning than the character $
> itself. If the from part has to stretch over more than one line, then
> each line ending has to be expressed with the linefeed character that
> separates the text into more than one line. Could be sometimes a
> carriage return (^M) has to be used, or some combination of carriage
> return and linefeed ...

Aha, I see. Now, more things I noticed in my few experiences with
RegExps become clear. Sometimes I search and replace longer regexps
and wonder why some are always skipped. Now I understand: these are
the ones extending over more than one line.

Thank you

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
       [not found]       ` <mailman.3307.1194823515.18990.help-gnu-emacs@gnu.org>
@ 2007-11-12  8:21         ` Harald Hanche-Olsen
  2007-11-12  9:55           ` Sven Bretfeld
                             ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Harald Hanche-Olsen @ 2007-11-12  8:21 UTC (permalink / raw)
  To: help-gnu-emacs

If you're having a hard time learning how regexps work, then
regex-tool seems like a great learning aid:

  ftp://ftp.newartisans.com/pub/regex-tool.el

I've only tried it for a couple of minutes, but it looks really
useful.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell

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

* Re: Why are RegExps never working?
  2007-11-11 23:24       ` Sven Bretfeld
@ 2007-11-12  9:39         ` Peter Dyballa
  2007-11-12  9:53           ` Sven Bretfeld
  0 siblings, 1 reply; 28+ messages in thread
From: Peter Dyballa @ 2007-11-12  9:39 UTC (permalink / raw)
  To: Sven Bretfeld; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 680 bytes --]


Am 12.11.2007 um 00:24 schrieb Sven Bretfeld:

> Sometimes I search and replace longer regexps
> and wonder why some are always skipped. Now I understand: these are
> the ones extending over more than one line.

Have you thought of using longlines? As far as I understand it  
presents you in GNU Emacs lines formatted to the width of the window  
or frame while in the buffer (or file) the lines have the length of a  
whole paragraph ...

--
Mit friedvollen Grüßen

   Pete

We are usually convinced more easily by reasons we have found  
ourselves than by those which have occurred to others.
                                           (Blaise Pascal)



[-- Attachment #1.2: Signierter Teil der Nachricht --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-12  9:39         ` Peter Dyballa
@ 2007-11-12  9:53           ` Sven Bretfeld
  0 siblings, 0 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-12  9:53 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 882 bytes --]

Hi Peter

Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 12.11.2007 um 00:24 schrieb Sven Bretfeld:
>
>> Sometimes I search and replace longer regexps
>> and wonder why some are always skipped. Now I understand: these are
>> the ones extending over more than one line.
>
> Have you thought of using longlines? As far as I understand it
> presents you in GNU Emacs lines formatted to the width of the window
> or frame while in the buffer (or file) the lines have the length of a
> whole paragraph ...

That would be quite inconvenient for other editing operations. My
files are usually quite unpredictable, since they come from different
authors writing in MS-Word. People seem to do very strange things when
they work with Word. So much of the editing must be done by
hand. But it might be a good idea to do at least the standard
replacements with long lines.

Greetings

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-12  8:21         ` Harald Hanche-Olsen
@ 2007-11-12  9:55           ` Sven Bretfeld
  2007-11-12 10:15             ` Lennart Borgman (gmail)
       [not found]           ` <mailman.3326.1194861370.18990.help-gnu-emacs@gnu.org>
  2007-11-13  8:55           ` Tim X
  2 siblings, 1 reply; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-12  9:55 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 455 bytes --]

Hi Harald

Harald Hanche-Olsen <hanche@math.ntnu.no> writes:

> If you're having a hard time learning how regexps work, then
> regex-tool seems like a great learning aid:
>
>   ftp://ftp.newartisans.com/pub/regex-tool.el
>
> I've only tried it for a couple of minutes, but it looks really
> useful.

Thank you for the suggestion. I've installed regex-tool and I have the
impression that it's a good way to become familiar with the topic.

Greetings

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-12  9:55           ` Sven Bretfeld
@ 2007-11-12 10:15             ` Lennart Borgman (gmail)
  2007-11-12 15:10               ` Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-12 10:15 UTC (permalink / raw)
  To: Sven Bretfeld; +Cc: help-gnu-emacs

Sven Bretfeld wrote:
> Hi Harald
> 
> Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
> 
>> If you're having a hard time learning how regexps work, then
>> regex-tool seems like a great learning aid:
>>
>>   ftp://ftp.newartisans.com/pub/regex-tool.el
>>
>> I've only tried it for a couple of minutes, but it looks really
>> useful.
> 
> Thank you for the suggestion. I've installed regex-tool and I have the
> impression that it's a good way to become familiar with the topic.

I have found the rx function in Emacs 22 useful when writing elisp code 
that uses regexps. It makes the regexps much easier to read IMO. You can 
also use that to learn how regexp.

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

* Re: Why are RegExps never working?
       [not found]           ` <mailman.3326.1194861370.18990.help-gnu-emacs@gnu.org>
@ 2007-11-12 13:04             ` Richard G Riley
  2007-11-12 18:54               ` Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Richard G Riley @ 2007-11-12 13:04 UTC (permalink / raw)
  To: help-gnu-emacs

Sven Bretfeld <sven.bretfeld@gmx.ch> writes:

> Hi Harald
>
> Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
>
>> If you're having a hard time learning how regexps work, then
>> regex-tool seems like a great learning aid:
>>
>>   ftp://ftp.newartisans.com/pub/regex-tool.el
>>
>> I've only tried it for a couple of minutes, but it looks really
>> useful.
>
> Thank you for the suggestion. I've installed regex-tool and I have the
> impression that it's a good way to become familiar with the topic.

just what I was looking for!!! Wonderful, thanks too!

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

* RE: Why are RegExps never working?
  2007-11-12 10:15             ` Lennart Borgman (gmail)
@ 2007-11-12 15:10               ` Drew Adams
  2007-11-12 16:01                 ` Sven Bretfeld
  0 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2007-11-12 15:10 UTC (permalink / raw)
  To: help-gnu-emacs

> >> If you're having a hard time learning how regexps work, then
> >> regex-tool seems like a great learning aid:
> >>
> >>   ftp://ftp.newartisans.com/pub/regex-tool.el
> >>
> >> I've only tried it for a couple of minutes, but it looks really
> >> useful.
> > 
> > Thank you for the suggestion. I've installed regex-tool and I have the
> > impression that it's a good way to become familiar with the topic.
> 
> I have found the rx function in Emacs 22 useful when writing elisp code 
> that uses regexps. It makes the regexps much easier to read IMO. You can 
> also use that to learn how regexp.

http://www.emacswiki.org/cgi-bin/emacs-en?CategoryRegexp

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

* Re: Why are RegExps never working?
  2007-11-12 15:10               ` Drew Adams
@ 2007-11-12 16:01                 ` Sven Bretfeld
  0 siblings, 0 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-12 16:01 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 814 bytes --]

"Drew Adams" <drew.adams@oracle.com> writes:

> http://www.emacswiki.org/cgi-bin/emacs-en?CategoryRegexp

Thanks, I know that excellent site already and worked it though as
good as I could some months ago.

But it's like always with these things. If you are a
non-computer-expert and have just learned the name of an IT topic (for
example, what a regexp is), these sites are not very easy to
understand, no matter how eager you are willing to learn.

That's, IMHO, the advantage of this list that comprises many nice
people who can give you the kick into the right direction. Especially
when you are in a social surrounding where people don't know more
about, say, html than that this is something written in the address
fields of their web-browsers from time to time.

Thanks to all, I give back what I can

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* RE: Why are RegExps never working?
  2007-11-12 13:04             ` Richard G Riley
@ 2007-11-12 18:54               ` Drew Adams
  0 siblings, 0 replies; 28+ messages in thread
From: Drew Adams @ 2007-11-12 18:54 UTC (permalink / raw)
  To: Richard G Riley, help-gnu-emacs

> >> If you're having a hard time learning how regexps work, then
> >> regex-tool seems like a great learning aid:
> >>
> >>   ftp://ftp.newartisans.com/pub/regex-tool.el
> >>
> >> I've only tried it for a couple of minutes, but it looks really
> >> useful.
> >
> > Thank you for the suggestion. I've installed regex-tool and I have the
> > impression that it's a good way to become familiar with the topic.
>
> just what I was looking for!!! Wonderful, thanks too!

Yes, nice.

Another tool that can help is Icicles search. Highlighting lets you see just
how your regexp groups match, for each search hit. Here is an example with
five nested regexp groups (screenshot with explanation):

http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Search_Commands%2c_Overview#
SearchHighlightingContextLevels.

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

* Re: Why are RegExps never working?
       [not found]     ` <mailman.3268.1194797266.18990.help-gnu-emacs@gnu.org>
@ 2007-11-12 23:53       ` Giorgos Keramidas
  2007-11-13 15:49         ` Peter Dyballa
  2007-11-14  9:22         ` Johan Bockgård
  0 siblings, 2 replies; 28+ messages in thread
From: Giorgos Keramidas @ 2007-11-12 23:53 UTC (permalink / raw)
  To: help-gnu-emacs

On Sun, 11 Nov 2007 16:52:04 +0100, Peter Dyballa <Peter_Dyballa@Web.DE> wrote:
>Am 11.11.2007 um 16:19 schrieb Sven Bretfeld:
>> This works perfectly (of course). I will search in the info
>> for the difference between a line feed and an end of line,
>> which is not clear to me.
>
> I'm not sure whether it's described so clearly. The main thing
> is that text is line oriented and therefore $ states end of
> line. [...]

There's a minor 'catch' here, which may prove interesting.  The
`character-classes' supported by the regexp engine of Emacs
consider the end of a line a [[:space:]] character, so you can do
replacements like:

    \([[:space:]][pP][pP]\.\)[[:space:]]+\([0-9]+\) -> \1~\2

This will DTRT, as far as the original poster's question is
concerned, but it may `join' some lines in the process.  A bit of
fill-paragraph can fix that too, and you are ready to go :-)

- Giorgos

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

* Re: Why are RegExps never working?
  2007-11-12  8:21         ` Harald Hanche-Olsen
  2007-11-12  9:55           ` Sven Bretfeld
       [not found]           ` <mailman.3326.1194861370.18990.help-gnu-emacs@gnu.org>
@ 2007-11-13  8:55           ` Tim X
  2007-11-13 13:54             ` Richard G Riley
  2 siblings, 1 reply; 28+ messages in thread
From: Tim X @ 2007-11-13  8:55 UTC (permalink / raw)
  To: help-gnu-emacs

Harald Hanche-Olsen <hanche@math.ntnu.no> writes:

> If you're having a hard time learning how regexps work, then
> regex-tool seems like a great learning aid:
>
>   ftp://ftp.newartisans.com/pub/regex-tool.el
>
> I've only tried it for a couple of minutes, but it looks really
> useful.
>

There is also re-builder, which is part of emacs.

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: Why are RegExps never working?
  2007-11-13  8:55           ` Tim X
@ 2007-11-13 13:54             ` Richard G Riley
  0 siblings, 0 replies; 28+ messages in thread
From: Richard G Riley @ 2007-11-13 13:54 UTC (permalink / raw)
  To: help-gnu-emacs

Tim X <timx@nospam.dev.null> writes:

> Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
>
>> If you're having a hard time learning how regexps work, then
>> regex-tool seems like a great learning aid:
>>
>>   ftp://ftp.newartisans.com/pub/regex-tool.el
>>
>> I've only tried it for a couple of minutes, but it looks really
>> useful.
>>
>
> There is also re-builder, which is part of emacs.
>
> Tim

Again, a great hint. Thanks. Does any one man know everything about
Emacs? :-)

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

* Re: Why are RegExps never working?
  2007-11-12 23:53       ` Giorgos Keramidas
@ 2007-11-13 15:49         ` Peter Dyballa
  2007-11-13 16:37           ` Giorgos Keramidas
  2007-11-14  9:22         ` Johan Bockgård
  1 sibling, 1 reply; 28+ messages in thread
From: Peter Dyballa @ 2007-11-13 15:49 UTC (permalink / raw)
  To: Giorgos Keramidas; +Cc: help-gnu-emacs


Am 13.11.2007 um 00:53 schrieb Giorgos Keramidas:

>     \([[:space:]][pP][pP]\.\)[[:space:]]+\([0-9]+\) -> \1~\2

Did you try it? For me it does correct Sven's example, which is this:

	text pp. 44 text text text text text text text text pp.
	54 text

It would work when the from part would not stretch over more than one  
line.

--
Greetings

   Pete

Bigamy is having one wife too many. Monogamy is the same.     — Oscar  
Wilde

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

* Re: Why are RegExps never working?
  2007-11-13 15:49         ` Peter Dyballa
@ 2007-11-13 16:37           ` Giorgos Keramidas
  2007-11-13 23:51             ` Sven Bretfeld
       [not found]             ` <mailman.3482.1194997914.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 28+ messages in thread
From: Giorgos Keramidas @ 2007-11-13 16:37 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs

On 2007-11-13 16:49, Peter Dyballa <Peter_Dyballa@Web.DE> wrote:
>
> Am 13.11.2007 um 00:53 schrieb Giorgos Keramidas:
>
>>     \([[:space:]][pP][pP]\.\)[[:space:]]+\([0-9]+\) -> \1~\2
>
> Did you try it? For me it does correct Sven's example, which is this:
>
> 	text pp. 44 text text text text text text text text pp.
> 	54 text
>
> It would work when the from part would not stretch over more than one line.

I did.

I used an Emacs snapshot from CVS, but I have this sort of regexp in my
~/NOTES file for several years.  The last time I updated the note was on
May 15, 2004.  It is strange that it doesn't work there.

I just tried once more, by running:

    emacs -q -nw

Then I pasted in a text-mode buffer the text:

    text pp. 44 text text text text text text text text pp.
    54 text

and after replacing the regexp shown above, my buffer now contains:

    text pp.~44 text text text text text text text text pp.~54 text

Odd, indeed...

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

* Re: Why are RegExps never working?
  2007-11-13 16:37           ` Giorgos Keramidas
@ 2007-11-13 23:51             ` Sven Bretfeld
  2007-11-14  9:55               ` Peter Dyballa
       [not found]             ` <mailman.3482.1194997914.18990.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-13 23:51 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 2077 bytes --]

Hi Peter and Giorgos

Giorgos Keramidas <keramida@ceid.upatras.gr> writes:

> On 2007-11-13 16:49, Peter Dyballa <Peter_Dyballa@Web.DE> wrote:
>>
>> Am 13.11.2007 um 00:53 schrieb Giorgos Keramidas:
>>
>>>     \([[:space:]][pP][pP]\.\)[[:space:]]+\([0-9]+\) -> \1~\2
>>
>> Did you try it? For me it does correct Sven's example, which is this:
>>
>> 	text pp. 44 text text text text text text text text pp.
>> 	54 text
>>
>> It would work when the from part would not stretch over more than one line.
>
> I did.
>
> I used an Emacs snapshot from CVS, but I have this sort of regexp in my
> ~/NOTES file for several years.  The last time I updated the note was on
> May 15, 2004.  It is strange that it doesn't work there.
>
> I just tried once more, by running:
>
>     emacs -q -nw
>
> Then I pasted in a text-mode buffer the text:
>
>     text pp. 44 text text text text text text text text pp.
>     54 text
>
> and after replacing the regexp shown above, my buffer now contains:
>
>     text pp.~44 text text text text text text text text pp.~54 text
>
> Odd, indeed...

It's partly working. But not with all major modes. It's working in a
Fundamental buffer, but neither in the *scratch* nor in an AucTeX
buffer. How Emacs is started doesn't seem to matter. That disturbs me.
Line endings should be \n in every mode, aren't they?

The info node Char Classes says:

`[:space:]'
     This matches any character that has whitespace syntax (*note
     Syntax Class Table::).

While a whitespace character is described thus:

 -- Syntax class: whitespace character
     "Whitespace characters" (designated by ` ' or `-') separate
     symbols and words from each other.  Typically, whitespace
     characters have no other syntactic significance, and multiple
     whitespace characters are syntactically equivalent to a single
     one.  Space, tab, newline and formfeed are classified as
     whitespace in almost all major modes.
                ^^^^^^^^^^^^^^^^^^^^^^^^^

Obviously not in the LaTeX major mode. It's a pity. Would have been a
nice shortcut.

Greetings

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
       [not found]             ` <mailman.3482.1194997914.18990.help-gnu-emacs@gnu.org>
@ 2007-11-14  3:13               ` Giorgos Keramidas
  0 siblings, 0 replies; 28+ messages in thread
From: Giorgos Keramidas @ 2007-11-14  3:13 UTC (permalink / raw)
  To: help-gnu-emacs

On Wed, 14 Nov 2007 00:51:27 +0100, Sven Bretfeld <sven.bretfeld@gmx.ch> wrote:
> It's partly working. But not with all major modes. [...]
>  -- Syntax class: whitespace character
>      "Whitespace characters" (designated by ` ' or `-') separate
>      symbols and words from each other.  Typically, whitespace
>      characters have no other syntactic significance, and multiple
>      whitespace characters are syntactically equivalent to a single
>      one.  Space, tab, newline and formfeed are classified as
>      whitespace in almost all major modes.
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^
> Obviously not in the LaTeX major mode. It's a pity. Would have been a
> nice shortcut.

Ah!  That's what was going on.  Nice catch :)

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

* Re: Why are RegExps never working?
  2007-11-12 23:53       ` Giorgos Keramidas
  2007-11-13 15:49         ` Peter Dyballa
@ 2007-11-14  9:22         ` Johan Bockgård
  2007-11-16  5:15           ` Tim X
  1 sibling, 1 reply; 28+ messages in thread
From: Johan Bockgård @ 2007-11-14  9:22 UTC (permalink / raw)
  To: help-gnu-emacs

Giorgos Keramidas <keramida@ceid.upatras.gr> writes:

> There's a minor 'catch' here, which may prove interesting.  The
> `character-classes' supported by the regexp engine of Emacs
> consider the end of a line a [[:space:]] character

There are several modes where this is not true, including Lisp and C. In
these modes newlines have `endcomment' syntax.

-- 
Johan Bockgård

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

* Re: Why are RegExps never working?
  2007-11-13 23:51             ` Sven Bretfeld
@ 2007-11-14  9:55               ` Peter Dyballa
  2007-11-14 17:52                 ` Sven Bretfeld
  0 siblings, 1 reply; 28+ messages in thread
From: Peter Dyballa @ 2007-11-14  9:55 UTC (permalink / raw)
  To: Sven Bretfeld; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 594 bytes --]


Am 14.11.2007 um 00:51 schrieb Sven Bretfeld:

> Space, tab, newline and formfeed are classified as
>      whitespace in almost all major modes.
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^

So good old and simple C-q C-j is a pretty good and lasting choice ...

>
> Obviously not in the LaTeX major mode. It's a pity. Would have been a
> nice shortcut.

Write a bug report to AUCTeX and see what evolves!

--
Mit friedvollen Grüßen

   Pete

The problem with the French is that they don't have a word for
«entrepreneur».                              - George W. Bush



[-- Attachment #1.2: Signierter Teil der Nachricht --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-14  9:55               ` Peter Dyballa
@ 2007-11-14 17:52                 ` Sven Bretfeld
  0 siblings, 0 replies; 28+ messages in thread
From: Sven Bretfeld @ 2007-11-14 17:52 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 377 bytes --]

Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 14.11.2007 um 00:51 schrieb Sven Bretfeld:
>
>> Space, tab, newline and formfeed are classified as
>>      whitespace in almost all major modes.
>>                 ^^^^^^^^^^^^^^^^^^^^^^^^^
>
> So good old and simple C-q C-j is a pretty good and lasting choice ...

Yes, that's working and I'm happy with it.

Greetings

Sven

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Why are RegExps never working?
  2007-11-14  9:22         ` Johan Bockgård
@ 2007-11-16  5:15           ` Tim X
  2007-11-16 10:17             ` Johan Bockgård
  0 siblings, 1 reply; 28+ messages in thread
From: Tim X @ 2007-11-16  5:15 UTC (permalink / raw)
  To: help-gnu-emacs

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Giorgos Keramidas <keramida@ceid.upatras.gr> writes:
>
>> There's a minor 'catch' here, which may prove interesting.  The
>> `character-classes' supported by the regexp engine of Emacs
>> consider the end of a line a [[:space:]] character
>
> There are several modes where this is not true, including Lisp and C. In
> these modes newlines have `endcomment' syntax.
>

isn't this controlled by the syntax table? As you can modify the syntax
table, you can modify how such things work. I seem to remember seeing a bit
of elisp that did this to make the regexp easier to write when needing to
do re-search. from memory, I think it temporarily changed the newline
syntax entry in the local syntax table, performed the search and since this
was all done within a saved context, everything is restored afterwards. I
remember it because at the time I remember thinking "thats a neat little
trick to simplify the regexp"

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: Why are RegExps never working?
  2007-11-16  5:15           ` Tim X
@ 2007-11-16 10:17             ` Johan Bockgård
  0 siblings, 0 replies; 28+ messages in thread
From: Johan Bockgård @ 2007-11-16 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

Tim X <timx@nospam.dev.null> writes:

> bojohan+news@dd.chalmers.se (Johan Bockgård) writes:
>
>> Giorgos Keramidas <keramida@ceid.upatras.gr> writes:
>>
>>> There's a minor 'catch' here, which may prove interesting.  The
>>> `character-classes' supported by the regexp engine of Emacs
>>> consider the end of a line a [[:space:]] character
>>
>> There are several modes where this is not true, including Lisp and C. In
>> these modes newlines have `endcomment' syntax.
>
> isn't this controlled by the syntax table?

Yes.

> As you can modify the syntax table, you can modify how such things
> work. I seem to remember seeing a bit of elisp that did this to make
> the regexp easier to write when needing to do re-search. from memory,
> I think it temporarily changed the newline syntax entry in the local
> syntax table, performed the search and since this was all done within
> a saved context, everything is restored afterwards.

(with-syntax-table (copy-syntax-table ...)
  (modify-syntax-entry ...))

-- 
Johan Bockgård

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

end of thread, other threads:[~2007-11-16 10:17 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-11 14:06 Why are RegExps never working? Sven Bretfeld
2007-11-11 14:47 ` Peter Dyballa
2007-11-11 15:19   ` Sven Bretfeld
2007-11-11 15:52     ` Peter Dyballa
2007-11-11 23:24       ` Sven Bretfeld
2007-11-12  9:39         ` Peter Dyballa
2007-11-12  9:53           ` Sven Bretfeld
     [not found]       ` <mailman.3307.1194823515.18990.help-gnu-emacs@gnu.org>
2007-11-12  8:21         ` Harald Hanche-Olsen
2007-11-12  9:55           ` Sven Bretfeld
2007-11-12 10:15             ` Lennart Borgman (gmail)
2007-11-12 15:10               ` Drew Adams
2007-11-12 16:01                 ` Sven Bretfeld
     [not found]           ` <mailman.3326.1194861370.18990.help-gnu-emacs@gnu.org>
2007-11-12 13:04             ` Richard G Riley
2007-11-12 18:54               ` Drew Adams
2007-11-13  8:55           ` Tim X
2007-11-13 13:54             ` Richard G Riley
     [not found]     ` <mailman.3268.1194797266.18990.help-gnu-emacs@gnu.org>
2007-11-12 23:53       ` Giorgos Keramidas
2007-11-13 15:49         ` Peter Dyballa
2007-11-13 16:37           ` Giorgos Keramidas
2007-11-13 23:51             ` Sven Bretfeld
2007-11-14  9:55               ` Peter Dyballa
2007-11-14 17:52                 ` Sven Bretfeld
     [not found]             ` <mailman.3482.1194997914.18990.help-gnu-emacs@gnu.org>
2007-11-14  3:13               ` Giorgos Keramidas
2007-11-14  9:22         ` Johan Bockgård
2007-11-16  5:15           ` Tim X
2007-11-16 10:17             ` Johan Bockgård
2007-11-11 15:21 ` Bastien
2007-11-11 14:38   ` Sven Bretfeld

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