all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Use the characters "+" and "-" in regular expressions
@ 2021-05-19 16:07 steve-humphreys
  2021-05-19 16:17 ` Skip Montanaro
  2021-05-19 19:17 ` [External] : " Drew Adams
  0 siblings, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-19 16:07 UTC (permalink / raw)
  To: Help Gnu Emacs

Is there a way to use the character "+" and "-" in regular expressions?



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:07 Use the characters "+" and "-" in regular expressions steve-humphreys
@ 2021-05-19 16:17 ` Skip Montanaro
  2021-05-19 16:26   ` steve-humphreys
  2021-05-19 16:27   ` tomas
  2021-05-19 19:17 ` [External] : " Drew Adams
  1 sibling, 2 replies; 50+ messages in thread
From: Skip Montanaro @ 2021-05-19 16:17 UTC (permalink / raw)
  To: steve-humphreys; +Cc: Help Gnu Emacs

> Is there a way to use the character "+" and "-" in regular expressions?
>

Yes, use character sets, e.g. [+] and [-]. If more characters are in a set
along with a hyphen, that hyphen needs to be the first element of the set
so as not to be interpreted as defining a range of characters. So, the
character set containing 0, 9 and hyphen is [-09] or [-90], not [0-9],
which would include all digits between 0 and 9, but not the hyphen.

Skip

>


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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:17 ` Skip Montanaro
@ 2021-05-19 16:26   ` steve-humphreys
  2021-05-19 16:47     ` Yuri Khan
  2021-05-19 19:25     ` Drew Adams
  2021-05-19 16:27   ` tomas
  1 sibling, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-19 16:26 UTC (permalink / raw)
  To: Skip Montanaro; +Cc: Help Gnu Emacs

   I want to match a space followed by a series of "+" or "-" or "."


   Sent: Thursday, May 20, 2021 at 4:17 AM
   From: "Skip Montanaro" <skip.montanaro@gmail.com>
   To: steve-humphreys@gmx.com
   Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
   Subject: Re: Use the characters "+" and "-" in regular expressions

     Is there a way to use the character "+" and "-" in regular
     expressions?


   Yes, use character sets, e.g. [+] and [-]. If more characters are in a
   set along with a hyphen, that hyphen needs to be the first element of
   the set so as not to be interpreted as defining a range of characters.
   So, the character set containing 0, 9 and hyphen is [-09] or [-90], not
   [0-9], which would include all digits between 0 and 9, but not the
   hyphen.

   Skip


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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:17 ` Skip Montanaro
  2021-05-19 16:26   ` steve-humphreys
@ 2021-05-19 16:27   ` tomas
  2021-05-19 16:39     ` Skip Montanaro
  1 sibling, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-19 16:27 UTC (permalink / raw)
  To: Skip Montanaro; +Cc: Help Gnu Emacs, steve-humphreys

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

On Wed, May 19, 2021 at 11:17:34AM -0500, Skip Montanaro wrote:
> > Is there a way to use the character "+" and "-" in regular expressions?

Plus "+" is special. Minus "-" is not.

> Yes, use character sets, e.g. [+] and [-]. If more characters are in a set
> along with a hyphen, that hyphen needs to be the first element of the set
> so as not to be interpreted as defining a range of characters. So, the
> character set containing 0, 9 and hyphen is [-09] or [-90], not [0-9],
> which would include all digits between 0 and 9, but not the hyphen.

Or escape with backslash. Note that due to string syntax you need
two of them.

Besides, the '-' isn't a special character in regexps (except whithin
brackets), so your bracket trick is rather counter-productive. Just
use as-is (except in brackets, where it should, as you say, go last,
to distinguish it from a range marker).

  (string-match "-" "Viala-du-Tarn")
  => 5

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:27   ` tomas
@ 2021-05-19 16:39     ` Skip Montanaro
  2021-05-19 17:43       ` Marcin Borkowski
  2021-05-19 19:10       ` tomas
  0 siblings, 2 replies; 50+ messages in thread
From: Skip Montanaro @ 2021-05-19 16:39 UTC (permalink / raw)
  To: tomas; +Cc: Help Gnu Emacs, steve-humphreys

> > Yes, use character sets, e.g. [+] and [-].

> Plus "+" is special. Minus "-" is not.
...
> Or escape with backslash. Note that due to string syntax you need
> two of them.

Yes, correct you are, Tomas. I long ago got used to putting most
punctuation in character sets regardless of its specialness, if for no
other reason than to help them stand out when rereading the code
later. I also find backslashes ugly (especially within Lisp strings
where there is no such thing as a "raw" string such as in Python, so
you wind up doubling them). Also, by reflexively putting punctuation
in character sets I rarely have to remember which are special, or in
what contexts. For example, "$" is special at the end of a regular
expression, but not elsewhere. Similarly, "^" is special only at the
start. The various special cases just make it kind of tedious and easy
to get wrong. By placing punctuation in character sets you declare to
the reader, "This is not special, no matter what you might think."
Well, except for hyphens inside character sets. :) Still, that reduces
the special cases from N to 1.

Skip



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:26   ` steve-humphreys
@ 2021-05-19 16:47     ` Yuri Khan
  2021-05-19 17:39       ` steve-humphreys
  2021-05-19 19:26       ` [External] : Re: Use the characters "+" and "-" in regular expressions Drew Adams
  2021-05-19 19:25     ` Drew Adams
  1 sibling, 2 replies; 50+ messages in thread
From: Yuri Khan @ 2021-05-19 16:47 UTC (permalink / raw)
  To: steve-humphreys; +Cc: Skip Montanaro, Help Gnu Emacs

On Wed, 19 May 2021 at 23:26, <steve-humphreys@gmx.com> wrote:
>
>    I want to match a space followed by a series of "+" or "-" or "."

You forgot to tell us what you tried, and how it doesn’t do what you want.

(You probably also forgot to read the manual chapters (info "(emacs)
Regexps") and (info "(elisp) Regular Expressions").)



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:47     ` Yuri Khan
@ 2021-05-19 17:39       ` steve-humphreys
  2021-05-19 19:16         ` tomas
  2021-05-19 19:30         ` Yuri Khan
  2021-05-19 19:26       ` [External] : Re: Use the characters "+" and "-" in regular expressions Drew Adams
  1 sibling, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-19 17:39 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Skip Montanaro, Help Gnu Emacs

I had tried

(string-match " [-\+\.]+" s)

> Sent: Thursday, May 20, 2021 at 4:47 AM
> From: "Yuri Khan" <yuri.v.khan@gmail.com>
> To: steve-humphreys@gmx.com
> Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Use the characters "+" and "-" in regular expressions
>
> On Wed, 19 May 2021 at 23:26, <steve-humphreys@gmx.com> wrote:
> >
> >    I want to match a space followed by a series of "+" or "-" or "."
> 
> You forgot to tell us what you tried, and how it doesn’t do what you want.
> 
> (You probably also forgot to read the manual chapters (info "(emacs)
> Regexps") and (info "(elisp) Regular Expressions").)
> 
>



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:39     ` Skip Montanaro
@ 2021-05-19 17:43       ` Marcin Borkowski
  2021-05-19 19:10       ` tomas
  1 sibling, 0 replies; 50+ messages in thread
From: Marcin Borkowski @ 2021-05-19 17:43 UTC (permalink / raw)
  To: Skip Montanaro; +Cc: Help Gnu Emacs, steve-humphreys


On 2021-05-19, at 18:39, Skip Montanaro <skip.montanaro@gmail.com> wrote:

>> > Yes, use character sets, e.g. [+] and [-].
>
>> Plus "+" is special. Minus "-" is not.
> ...
>> Or escape with backslash. Note that due to string syntax you need
>> two of them.
>
> Yes, correct you are, Tomas. I long ago got used to putting most
> punctuation in character sets regardless of its specialness, if for no
> other reason than to help them stand out when rereading the code
> later. I also find backslashes ugly (especially within Lisp strings
> where there is no such thing as a "raw" string such as in Python, so
> you wind up doubling them). Also, by reflexively putting punctuation
> in character sets I rarely have to remember which are special, or in
> what contexts. For example, "$" is special at the end of a regular
> expression, but not elsewhere. Similarly, "^" is special only at the
> start. The various special cases just make it kind of tedious and easy
> to get wrong. By placing punctuation in character sets you declare to
> the reader, "This is not special, no matter what you might think."
> Well, except for hyphens inside character sets. :) Still, that reduces

And except the caret right after the `['.

> the special cases from N to 1.

So, N to 2.  (Still a win, though.)

Best,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:39     ` Skip Montanaro
  2021-05-19 17:43       ` Marcin Borkowski
@ 2021-05-19 19:10       ` tomas
  1 sibling, 0 replies; 50+ messages in thread
From: tomas @ 2021-05-19 19:10 UTC (permalink / raw)
  To: Skip Montanaro; +Cc: Help Gnu Emacs, steve-humphreys

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]

On Wed, May 19, 2021 at 11:39:46AM -0500, Skip Montanaro wrote:
> > > Yes, use character sets, e.g. [+] and [-].
> 
> > Plus "+" is special. Minus "-" is not.
> ...
> > Or escape with backslash. Note that due to string syntax you need
> > two of them.
> 
> Yes, correct you are, Tomas. I long ago got used to putting most
> punctuation in character sets regardless of its specialness, if for no
> other reason than to help them stand out when rereading the code
> later [...]

Right: brackets help curbing the multiplication of backslashes.

I've found another strange application for that: "ps waux | grep foo"
will find your "grep foo" in the process list. Decorating one of your
characters in "foo" with brackets will fix that. Hacky, but it works :)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 17:39       ` steve-humphreys
@ 2021-05-19 19:16         ` tomas
  2021-05-19 19:27           ` tomas
  2021-05-19 19:30         ` Yuri Khan
  1 sibling, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-19 19:16 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]

On Wed, May 19, 2021 at 07:39:10PM +0200, steve-humphreys@gmx.com wrote:
> > Sent: Thursday, May 20, 2021 at 4:47 AM
> > From: "Yuri Khan" <yuri.v.khan@gmail.com>
> > To: steve-humphreys@gmx.com
> > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> > Subject: Re: Use the characters "+" and "-" in regular expressions
> >
> > On Wed, 19 May 2021 at 23:26, <steve-humphreys@gmx.com> wrote:
> > >
> > >    I want to match a space followed by a series of "+" or "-" or "."
> > 
> > You forgot to tell us what you tried, and how it doesn’t do what you want.
> > 
> > (You probably also forgot to read the manual chapters (info "(emacs)
> > Regexps") and (info "(elisp) Regular Expressions").)
> I had tried
> 
> (string-match " [-\+\.]+" s)

But you forgot to read the manual, as Skip noted. Otherwise you would have
read that whithin the [], + and . are not special. Don't escape them.
But the - is special. Put it at the end.

So your bracket sub-expression should be [+.-].

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* RE: [External] : Use the characters "+" and "-" in regular expressions
  2021-05-19 16:07 Use the characters "+" and "-" in regular expressions steve-humphreys
  2021-05-19 16:17 ` Skip Montanaro
@ 2021-05-19 19:17 ` Drew Adams
  1 sibling, 0 replies; 50+ messages in thread
From: Drew Adams @ 2021-05-19 19:17 UTC (permalink / raw)
  To: steve-humphreys@gmx.com, Help Gnu Emacs

> Is there a way to use the character "+" and "-" in regular expressions?

Ask Emacs!

1. `C-h i' Choose Elisp manual.
2. `i regexp TAB', and complete to
   `regexp, special characters in'
3. Read about `\':

   it quotes the special characters

   Because ‘\’ quotes special characters, ‘\$’ is a
   regular expression that matches only ‘$’, and ‘\[’ is
   a regular expression that matches only ‘[’, and so on.

IOW, `\+' and `\-' match (only) `+' and `-', respectively.

Another way to match special chars literally is to include
them in a character alternative, also described in the same
page of the manual.

`[+]' matches only `+', `[-]' matches only `+' or `-', and
`[-+]' and `[+-]' match either `+' or `-'.

Note too that `-' in a char alternative behaves specially:

   To include a ‘-’, write ‘-’ as the first or last
   character of the character alternative, or as the
   upper bound of a range.  Thus, ‘[]-]’ matches both
   ‘]’ and ‘-’.

In `[-+]' and `[+-]', the `-' is the first or last char in
the alternative.

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

* RE: [External] : Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:26   ` steve-humphreys
  2021-05-19 16:47     ` Yuri Khan
@ 2021-05-19 19:25     ` Drew Adams
  1 sibling, 0 replies; 50+ messages in thread
From: Drew Adams @ 2021-05-19 19:25 UTC (permalink / raw)
  To: steve-humphreys@gmx.com, Skip Montanaro; +Cc: Help Gnu Emacs

>> Yes, use character sets, e.g. [+] and [-].
>
> I want to match a space followed by a series of "+" or "-" or "."

Yes, and?  The answer is right above your question.

Do you mean a series of one or more or a series of
zero or more?  (Or 42 or more or...?)  Your problem
statements are piecemeal.

[-+.]* is zero or more.  [-+.]+ is one or more.

As Tomas pointed out, you need not escape the `-'.
But it's easier if you do.  If not, you need to group
the pattern that gets repeated:

\(-[+.]\)* is zero or more.  \(-[+.]\)+ is one or more.

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

* RE: [External] : Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 16:47     ` Yuri Khan
  2021-05-19 17:39       ` steve-humphreys
@ 2021-05-19 19:26       ` Drew Adams
  1 sibling, 0 replies; 50+ messages in thread
From: Drew Adams @ 2021-05-19 19:26 UTC (permalink / raw)
  To: Yuri Khan, steve-humphreys@gmx.com; +Cc: Skip Montanaro, Help Gnu Emacs

> You forgot to tell us what you tried, and how it doesn’t do what you
> want.
> 
> (You probably also forgot to read the manual chapters (info "(emacs)
> Regexps") and (info "(elisp) Regular Expressions").)

+1.


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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 19:16         ` tomas
@ 2021-05-19 19:27           ` tomas
  0 siblings, 0 replies; 50+ messages in thread
From: tomas @ 2021-05-19 19:27 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

On Wed, May 19, 2021 at 09:16:22PM +0200, tomas wrote:
> On Wed, May 19, 2021 at 07:39:10PM +0200, steve-humphreys@gmx.com wrote:
> > > Sent: Thursday, May 20, 2021 at 4:47 AM
> > > From: "Yuri Khan" <yuri.v.khan@gmail.com>

[...]

> But you forgot to read the manual, as Skip noted [...]

Ugh. "...as Yuri noted". Sorry for the mis-attribution.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 17:39       ` steve-humphreys
  2021-05-19 19:16         ` tomas
@ 2021-05-19 19:30         ` Yuri Khan
  2021-05-19 21:32           ` tomas
  1 sibling, 1 reply; 50+ messages in thread
From: Yuri Khan @ 2021-05-19 19:30 UTC (permalink / raw)
  To: steve-humphreys; +Cc: Skip Montanaro, Help Gnu Emacs

On Thu, 20 May 2021 at 00:39, <steve-humphreys@gmx.com> wrote:
>
> I had tried
>
> (string-match " [-\+\.]+" s)

This ought to work, even though you’re using backslashes incorrectly.

* + and . are not special inside a character class; you don’t need to
escape them.
* If you wanted to escape them in a regexp that is inside a string,
you should have put two backslashes.
* Escaping them with a single backslash only acts on the string syntax
level; because + and . are not special in a string, they pass through
as themselves so the regexp is the same as if you had written "
[-+.]+".


(string-match " [-+.]+" ";; ----")
⇒ 2
(string-match " [-+.]+" ";; ++++")
⇒ 2
(string-match " [-+.]+" ";; ....")
⇒ 2
(string-match " [-+.]+" ";; -+-+")
⇒ 2



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

* Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 19:30         ` Yuri Khan
@ 2021-05-19 21:32           ` tomas
  2021-05-19 21:59             ` [External] : " Drew Adams
  0 siblings, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-19 21:32 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]

On Thu, May 20, 2021 at 02:30:22AM +0700, Yuri Khan wrote:
> On Thu, 20 May 2021 at 00:39, <steve-humphreys@gmx.com> wrote:
> >
> > I had tried
> >
> > (string-match " [-\+\.]+" s)
> 
> This ought to work, even though you’re using backslashes incorrectly.

Hm. According to the docs, the dash should go last, but a test
actually confirms that it works in first position.

OTOH, the regex(7) man page says "first or last" position. Since
the underlying lib is probably the same, I'd guess that this is
an omission in the Emacs doc.

> * + and . are not special inside a character class; you don’t need to
> escape them.

Exactly.

> * If you wanted to escape them in a regexp that is inside a string,
> you should have put two backslashes.
>
> * Escaping them with a single backslash only acts on the string syntax
> level; because + and . are not special in a string, they pass through
> as themselves so the regexp is the same as if you had written "
> [-+.]+".

So, as seen by the regexp they weren't escaped anyway ;-)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* RE: [External] : Re: Use the characters "+" and "-" in regular expressions
  2021-05-19 21:32           ` tomas
@ 2021-05-19 21:59             ` Drew Adams
  2021-05-20  6:26               ` RE: [External] : " steve-humphreys
  2021-05-20  7:15               ` Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions] tomas
  0 siblings, 2 replies; 50+ messages in thread
From: Drew Adams @ 2021-05-19 21:59 UTC (permalink / raw)
  To: tomas@tuxteam.de, help-gnu-emacs@gnu.org

> Hm. According to the docs, the dash should go last, but 
> a test actually confirms that it works in first position.

I quoted this from (elisp) `Regexp Special':

   To include a ‘-’, write ‘-’ as the first or last
                                      ^^^^^^^^^^^^^
   character of the character alternative, or as the
   upper bound of a range.  Thus, ‘[]-]’ matches both
   ‘]’ and ‘-’.

That's from Emacs 26 (and all prior releases, at least
as far back as Emacs 20).  But yes, they changed that
text for Emacs 27, to this:

   To include ‘-’, put it at the end.
                          ^^^^^^^^^^
___

For Emacs 20, it says this:

   To include a `-', write `-' as the first or last
   character of the character alternative, or put it
   after a range.  Thus, `[]-]' matches both `]' and
   `-'.

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

* Re: RE: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-19 21:59             ` [External] : " Drew Adams
@ 2021-05-20  6:26               ` steve-humphreys
  2021-05-20  7:59                 ` steve-humphreys
  2021-05-20  7:15               ` Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions] tomas
  1 sibling, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20  6:26 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs@gnu.org

Have done as follows but cannot see the result.  Have read through
the table of valid format specifications, and the other options are
mostly about printing numbers.

(message " ")
(message "*** ***")
(setq s (string-match "[+]+"  "++++++++++++++++"))
message("%s" s)
(setq s (string-match "[+-]+" "++++++++++++++++"))
message("%s" s)
(setq s (string-match "[+-]+" "----------------"))
message("%s"  s)






> Sent: Thursday, May 20, 2021 at 9:59 AM
> From: "Drew Adams" <drew.adams@oracle.com>
> To: "tomas@tuxteam.de" <tomas@tuxteam.de>, "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: RE: [External] : Re: Use the characters "+" and "-" in regular expressions
>
> > Hm. According to the docs, the dash should go last, but 
> > a test actually confirms that it works in first position.
> 
> I quoted this from (elisp) `Regexp Special':
> 
>    To include a ‘-’, write ‘-’ as the first or last
>                                       ^^^^^^^^^^^^^
>    character of the character alternative, or as the
>    upper bound of a range.  Thus, ‘[]-]’ matches both
>    ‘]’ and ‘-’.
> 
> That's from Emacs 26 (and all prior releases, at least
> as far back as Emacs 20).  But yes, they changed that
> text for Emacs 27, to this:
> 
>    To include ‘-’, put it at the end.
>                           ^^^^^^^^^^
> ___
> 
> For Emacs 20, it says this:
> 
>    To include a `-', write `-' as the first or last
>    character of the character alternative, or put it
>    after a range.  Thus, `[]-]' matches both `]' and
>    `-'.
>



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

* Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions]
  2021-05-19 21:59             ` [External] : " Drew Adams
  2021-05-20  6:26               ` RE: [External] : " steve-humphreys
@ 2021-05-20  7:15               ` tomas
  2021-05-20  8:08                 ` Robert Pluim
  1 sibling, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-20  7:15 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

On Wed, May 19, 2021 at 09:59:11PM +0000, Drew Adams wrote:
> > Hm. According to the docs, the dash should go last, but 
> > a test actually confirms that it works in first position.
> 
> I quoted this from (elisp) `Regexp Special':
> 
>    To include a ‘-’, write ‘-’ as the first or last
>                                       ^^^^^^^^^^^^^
>    character of the character alternative, or as the
>    upper bound of a range.  Thus, ‘[]-]’ matches both
>    ‘]’ and ‘-’.
> 
> That's from Emacs 26 (and all prior releases, at least
> as far back as Emacs 20).  But yes, they changed that
> text for Emacs 27, to this:
> 
>    To include ‘-’, put it at the end.
>                           ^^^^^^^^^^
> ___
> 
> For Emacs 20, it says this:
> 
>    To include a `-', write `-' as the first or last
>    character of the character alternative, or put it
>    after a range.  Thus, `[]-]' matches both `]' and
>    `-'.

Oh. That is interesting. Anyone knows why that change?

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  6:26               ` RE: [External] : " steve-humphreys
@ 2021-05-20  7:59                 ` steve-humphreys
  2021-05-20  8:26                   ` tomas
  0 siblings, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20  7:59 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

I wonder why I am getting 

Symbol's value as variable is void: message

(message " ")
(message "*** ***")
(setq s (string-match "[+]+"  "++++++++++++++++"))
message("%s" s)
(setq s (string-match "[+-]+" "++++++++++++++++"))
message("%s" s)
(setq s (string-match "[+-]+" "----------------"))
message("%s"  s)
 
> 
> 
> 
> 
> 
> > Sent: Thursday, May 20, 2021 at 9:59 AM
> > From: "Drew Adams" <drew.adams@oracle.com>
> > To: "tomas@tuxteam.de" <tomas@tuxteam.de>, "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: RE: [External] : Re: Use the characters "+" and "-" in regular expressions
> >
> > > Hm. According to the docs, the dash should go last, but 
> > > a test actually confirms that it works in first position.
> > 
> > I quoted this from (elisp) `Regexp Special':
> > 
> >    To include a ‘-’, write ‘-’ as the first or last
> >                                       ^^^^^^^^^^^^^
> >    character of the character alternative, or as the
> >    upper bound of a range.  Thus, ‘[]-]’ matches both
> >    ‘]’ and ‘-’.
> > 
> > That's from Emacs 26 (and all prior releases, at least
> > as far back as Emacs 20).  But yes, they changed that
> > text for Emacs 27, to this:
> > 
> >    To include ‘-’, put it at the end.
> >                           ^^^^^^^^^^
> > ___
> > 
> > For Emacs 20, it says this:
> > 
> >    To include a `-', write `-' as the first or last
> >    character of the character alternative, or put it
> >    after a range.  Thus, `[]-]' matches both `]' and
> >    `-'.
> >
> 
>



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

* Re: Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions]
  2021-05-20  7:15               ` Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions] tomas
@ 2021-05-20  8:08                 ` Robert Pluim
  0 siblings, 0 replies; 50+ messages in thread
From: Robert Pluim @ 2021-05-20  8:08 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org

>>>>> On Thu, 20 May 2021 09:15:29 +0200, "tomas@tuxteam.de" <tomas@tuxteam.de> said:

    >> I quoted this from (elisp) `Regexp Special':
    >> 
    >> To include a ‘-’, write ‘-’ as the first or last
    >> ^^^^^^^^^^^^^
    >> character of the character alternative, or as the
    >> upper bound of a range.  Thus, ‘[]-]’ matches both
    >> ‘]’ and ‘-’.
    >> 
    >> That's from Emacs 26 (and all prior releases, at least
    >> as far back as Emacs 20).  But yes, they changed that
    >> text for Emacs 27, to this:
    >> 
    >> To include ‘-’, put it at the end.
    >> ^^^^^^^^^^
    >> ___
    >> 
    >> For Emacs 20, it says this:
    >> 
    >> To include a `-', write `-' as the first or last
    >> character of the character alternative, or put it
    >> after a range.  Thus, `[]-]' matches both `]' and
    >> `-'.

    tomas@tuxteam> Oh. That is interesting. Anyone knows why that change?

It makes the description and usage simpler and more regular, and less
error-prone.

Since I never remember the rules for this stuff anyway, I do this
instead:

(rx (or ?- ?+ ?.))
=> "[+.-]"

but of course parenthesis-like characters still need to be escaped:

(rx (or ?\) ?\] ?-))
=> "[])-]"

Robert
-- 



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  7:59                 ` steve-humphreys
@ 2021-05-20  8:26                   ` tomas
  2021-05-20  8:41                     ` steve-humphreys
  2021-05-20  9:42                     ` steve-humphreys
  0 siblings, 2 replies; 50+ messages in thread
From: tomas @ 2021-05-20  8:26 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On Thu, May 20, 2021 at 09:59:59AM +0200, steve-humphreys@gmx.com wrote:
> I wonder why I am getting 
> 
> Symbol's value as variable is void: message

Because you are using it as a variable down there:
> 
> (message " ")
> (message "*** ***")
> (setq s (string-match "[+]+"  "++++++++++++++++"))
> message("%s" s)
  ^^^ HERE
> (setq s (string-match "[+-]+" "++++++++++++++++"))
> message("%s" s)
> (setq s (string-match "[+-]+" "----------------"))
> message("%s"  s)
  ^^^ AND HERE

Now *STOP*.

Think about it. How could you have debugged it yourself?

That's the only way to improve.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  8:26                   ` tomas
@ 2021-05-20  8:41                     ` steve-humphreys
  2021-05-20  9:42                     ` steve-humphreys
  1 sibling, 0 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20  8:41 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org

You are right.  Have got it now, thanks.

> Sent: Thursday, May 20, 2021 at 8:26 PM
> From: tomas@tuxteam.de
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> On Thu, May 20, 2021 at 09:59:59AM +0200, steve-humphreys@gmx.com wrote:
> > I wonder why I am getting
> >
> > Symbol's value as variable is void: message
>
> Because you are using it as a variable down there:
> >
> > (message " ")
> > (message "*** ***")
> > (setq s (string-match "[+]+"  "++++++++++++++++"))
> > message("%s" s)
>   ^^^ HERE
> > (setq s (string-match "[+-]+" "++++++++++++++++"))
> > message("%s" s)
> > (setq s (string-match "[+-]+" "----------------"))
> > message("%s"  s)
>   ^^^ AND HERE
>
> Now *STOP*.
>
> Think about it. How could you have debugged it yourself?
>
> That's the only way to improve.
>
> Cheers
>  - t
>



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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  8:26                   ` tomas
  2021-05-20  8:41                     ` steve-humphreys
@ 2021-05-20  9:42                     ` steve-humphreys
  2021-05-20  9:56                       ` tomas
  2021-05-20 12:39                       ` [External] : Use the characters "+" and "-" in regular expressions Jean Louis
  1 sibling, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20  9:42 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org

I have now used ";; [;+-.]+" to match some specific lines.

(string-match ";; [;+-.]+" s")

How could I negate the regexp that I have defined?

> Sent: Thursday, May 20, 2021 at 8:26 PM
> From: tomas@tuxteam.de
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> On Thu, May 20, 2021 at 09:59:59AM +0200, steve-humphreys@gmx.com wrote:
> > I wonder why I am getting
> >
> > Symbol's value as variable is void: message
>
> Because you are using it as a variable down there:
> >
> > (message " ")
> > (message "*** ***")
> > (setq s (string-match "[+]+"  "++++++++++++++++"))
> > message("%s" s)
>   ^^^ HERE
> > (setq s (string-match "[+-]+" "++++++++++++++++"))
> > message("%s" s)
> > (setq s (string-match "[+-]+" "----------------"))
> > message("%s"  s)
>   ^^^ AND HERE
>
> Now *STOP*.
>
> Think about it. How could you have debugged it yourself?
>
> That's the only way to improve.
>
> Cheers
>  - t
>



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  9:42                     ` steve-humphreys
@ 2021-05-20  9:56                       ` tomas
  2021-05-20 10:11                         ` steve-humphreys
  2021-05-20 10:29                         ` Negating a regexp Yuri Khan
  2021-05-20 12:39                       ` [External] : Use the characters "+" and "-" in regular expressions Jean Louis
  1 sibling, 2 replies; 50+ messages in thread
From: tomas @ 2021-05-20  9:56 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

On Thu, May 20, 2021 at 11:42:58AM +0200, steve-humphreys@gmx.com wrote:
> I have now used ";; [;+-.]+" to match some specific lines.
> 
> (string-match ";; [;+-.]+" s")
                       ^ NOOOO!

This is a dash in the middle, indicating a range (i.e. "match all
characters in the range "+" to "."). In ASCII (and by extension,
in UTF-8), these are "+", ",", "-" and ".".

So this will match...

  (string-match "[+-.]" "Folks, let's go!")
  => 5

... the comma!

This is the whole discussion we've had just yesterday and today.
I'm a bit confused: you seem to have ignored it totally.

> How could I negate the regexp that I have defined?

I don't even know what you mean by "negating a regexp".

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  9:56                       ` tomas
@ 2021-05-20 10:11                         ` steve-humphreys
  2021-05-20 10:22                           ` tomas
  2021-05-20 10:29                         ` Negating a regexp Yuri Khan
  1 sibling, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 10:11 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org



> Sent: Thursday, May 20, 2021 at 9:56 PM
> From: tomas@tuxteam.de
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> On Thu, May 20, 2021 at 11:42:58AM +0200, steve-humphreys@gmx.com wrote:
> > I have now used ";; [;+-.]+" to match some specific lines.
> >
> > (string-match ";; [;+-.]+" s")
>                        ^ NOOOO!
>
> This is a dash in the middle, indicating a range (i.e. "match all
> characters in the range "+" to "."). In ASCII (and by extension,
> in UTF-8), these are "+", ",", "-" and ".".

I thought it was only about numeric and letter ranges only.

> So this will match...
>
>   (string-match "[+-.]" "Folks, let's go!")
>   => 5
>
> ... the comma!
>
> This is the whole discussion we've had just yesterday and today.
> I'm a bit confused: you seem to have ignored it totally.
>
> > How could I negate the regexp that I have defined?
>
> I don't even know what you mean by "negating a regexp".
>
> Cheers
>  - t
>



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 10:11                         ` steve-humphreys
@ 2021-05-20 10:22                           ` tomas
  2021-05-20 10:37                             ` steve-humphreys
  0 siblings, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-20 10:22 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1397 bytes --]

On Thu, May 20, 2021 at 12:11:49PM +0200, steve-humphreys@gmx.com wrote:
> 
> 
> > Sent: Thursday, May 20, 2021 at 9:56 PM
> > From: tomas@tuxteam.de
> > To: steve-humphreys@gmx.com
> > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> >
> > On Thu, May 20, 2021 at 11:42:58AM +0200, steve-humphreys@gmx.com wrote:
> > > I have now used ";; [;+-.]+" to match some specific lines.
> > >
> > > (string-match ";; [;+-.]+" s")
> >                        ^ NOOOO!
> >
> > This is a dash in the middle, indicating a range (i.e. "match all
> > characters in the range "+" to "."). In ASCII (and by extension,
> > in UTF-8), these are "+", ",", "-" and ".".
> 
> I thought it was only about numeric and letter ranges only.

No. Any characters can be the endpoints of a range. But this is
somewhat dangerous, since, strictly speaking, the results might
depend on the character encoding. Nowadays, with ubiquitous Unicode,
this is less of a problem. In the context of Emacs, which probably
always uses its internal set (a superset of Unicode), results are
probably always consistent.

That doesn't mean they are always intuitive. Quick: is "d" in
the range "[(-{]"?

Don't do that. Your reader will thank you.

Again: please, play with it. Make yourself test cases.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Negating a regexp
  2021-05-20  9:56                       ` tomas
  2021-05-20 10:11                         ` steve-humphreys
@ 2021-05-20 10:29                         ` Yuri Khan
  2021-05-20 10:39                           ` tomas
  1 sibling, 1 reply; 50+ messages in thread
From: Yuri Khan @ 2021-05-20 10:29 UTC (permalink / raw)
  To: tomas; +Cc: emacs-tangents, steve-humphreys

> > How could I negate the regexp that I have defined?
>
> I don't even know what you mean by "negating a regexp".

The automata theory, where the notion of a regexp comes from, defines
a “regular set” as one that can be described using a regexp (where
regexps are defined to be implicitly anchored to beginning and end of
string, and support concatenation, alternative, and iteration, but not
backreferences). It then proves that for each regexp there exists an
equivalent nondeterministic finite automaton, and for every NDFA there
exists an equivalent DFA, and for every DFA there exists an equivalent
regexp. It also proves that the class of regular sets is closed under
set theory operations — union, intersection, and complement.

It follows that, theoretically, a regexp ‘R’ can be negated — one can
construct a regexp ‘(not R)’ that matches exactly all strings that R
does not match.

However, the proofs and constructions are complex enough that in
practice such a regexp would be unreadable.

As an example, consider the regexp ‘a’ which matches only a single
one-character string. Its complement would be a regexp that matches
the empty string, all one-character strings whose character is not
‘a’, and all strings longer than one character. The shortest way to
express that idea that I can think of is ‘|[^a]|.{2,}’ and that’s
ignoring the issue of newlines.

So, to steve-humphreys: There is no practical general way to negate a
regexp. You need to either negate the result of attempting to match,
or to think hard and write a new regexp that matches what you want.



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 10:22                           ` tomas
@ 2021-05-20 10:37                             ` steve-humphreys
  2021-05-20 10:50                               ` tomas
  2021-05-20 12:46                               ` Jean Louis
  0 siblings, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 10:37 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org



> Sent: Thursday, May 20, 2021 at 10:22 PM
> From: tomas@tuxteam.de
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> On Thu, May 20, 2021 at 12:11:49PM +0200, steve-humphreys@gmx.com wrote:
> >
> >
> > > Sent: Thursday, May 20, 2021 at 9:56 PM
> > > From: tomas@tuxteam.de
> > > To: steve-humphreys@gmx.com
> > > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> > >
> > > On Thu, May 20, 2021 at 11:42:58AM +0200, steve-humphreys@gmx.com wrote:
> > > > I have now used ";; [;+-.]+" to match some specific lines.
> > > >
> > > > (string-match ";; [;+-.]+" s")
> > >                        ^ NOOOO!
> > >
> > > This is a dash in the middle, indicating a range (i.e. "match all
> > > characters in the range "+" to "."). In ASCII (and by extension,
> > > in UTF-8), these are "+", ",", "-" and ".".
> >
> > I thought it was only about numeric and letter ranges only.
>
> No. Any characters can be the endpoints of a range. But this is
> somewhat dangerous, since, strictly speaking, the results might
> depend on the character encoding. Nowadays, with ubiquitous Unicode,
> this is less of a problem. In the context of Emacs, which probably
> always uses its internal set (a superset of Unicode), results are
> probably always consistent.
>
> That doesn't mean they are always intuitive. Quick: is "d" in
> the range "[(-{]"?
>
> Don't do that. Your reader will thank you.
>
> Again: please, play with it. Make yourself test cases.

Done some tests and got some strange results that thought would not match.  Then things
made more sense after your clarification because when I looked at some of the strings,
there was a comma in them.

Am seeing how to match strings of blank lines

But " +" does not do the job.  I know why, but how can one match strings of blanks?


> Cheers
>  - t
>



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

* Re: Negating a regexp
  2021-05-20 10:29                         ` Negating a regexp Yuri Khan
@ 2021-05-20 10:39                           ` tomas
  0 siblings, 0 replies; 50+ messages in thread
From: tomas @ 2021-05-20 10:39 UTC (permalink / raw)
  To: Yuri Khan; +Cc: emacs-tangents, steve-humphreys

[-- Attachment #1: Type: text/plain, Size: 970 bytes --]

On Thu, May 20, 2021 at 05:29:50PM +0700, Yuri Khan wrote:
> > > How could I negate the regexp that I have defined?
> >
> > I don't even know what you mean by "negating a regexp".
> 
> The automata theory, where the notion of a regexp comes from, defines
> a “regular set” [...]

A beautiful theory, indeed. In that context, "negation" has a definite
meaning (but, as you wrote: anchoring, yadda, yadda).

I'm almost sure this is *not* what steve-humphreys had in mind (but
hey, I've been wrong before [1]!).

> So, to steve-humphreys: There is no practical general way to negate a
> regexp. You need to either negate the result of attempting to match,
> or to think hard and write a new regexp that matches what you want.

Exactly. I think that, to get some help here, steve will have to
refine his idea a bit for us to have a chance of making some sense
of it.

Cheers
[1] This is, as you might suspect, a shameless understatement :)
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 10:37                             ` steve-humphreys
@ 2021-05-20 10:50                               ` tomas
  2021-05-20 11:19                                 ` steve-humphreys
  2021-05-20 12:46                               ` Jean Louis
  1 sibling, 1 reply; 50+ messages in thread
From: tomas @ 2021-05-20 10:50 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1465 bytes --]

On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:

[...]

> Done some tests and got some strange results that thought would not match.  Then things
> made more sense after your clarification because when I looked at some of the strings,
> there was a comma in them.

OK. Glad I could help.

> Am seeing how to match strings of blank lines

What is "a string of blank lines"?

I know strings of characters. But a line is not a character.

Do you mean "several blank lines next to each other"? I don't
think so. But what do you mean?

> But " +" does not do the job.

Again: you know by now that this will match "one or more spaces". Is
that for you a "string of blanks" (huh: where did you leave the
"line" from above?) or not?

>                  I know why, but how can one match strings of blanks?

To even have a chance to do that, you'll have to get hold of a more
or less precise idea of what "a string of blanks" is. This is work.

Begin with:

  (string-match " +" "A summer full of butterflies")
  => 1

Bingo: the first run of one-or-more spaces is at the position 1
(the first position in the string is 0, the "A"). So it's working
as it should.

So what is /your/ idea of "a string of blank lines" or "a string
of blanks"? Only you can find out.

If you feel you are stuck in that task, it sometimes help to collect
a couple of examples and counter-examples (they'll come in handy
when you try to test your attempts).

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 10:50                               ` tomas
@ 2021-05-20 11:19                                 ` steve-humphreys
  2021-05-20 11:27                                   ` steve-humphreys
  2021-05-20 11:31                                   ` Christopher Dimech
  0 siblings, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 11:19 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs@gnu.org

This is a string of blanks, a string composed of whitespace of any length.

"                     "



> Sent: Thursday, May 20, 2021 at 10:50 PM
> From: tomas@tuxteam.de
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:
>
> [...]
>
> > Done some tests and got some strange results that thought would not match.  Then things
> > made more sense after your clarification because when I looked at some of the strings,
> > there was a comma in them.
>
> OK. Glad I could help.
>
> > Am seeing how to match strings of blank lines
>
> What is "a string of blank lines"?
>
> I know strings of characters. But a line is not a character.
>
> Do you mean "several blank lines next to each other"? I don't
> think so. But what do you mean?
>
> > But " +" does not do the job.
>
> Again: you know by now that this will match "one or more spaces". Is
> that for you a "string of blanks" (huh: where did you leave the
> "line" from above?) or not?
>
> >                  I know why, but how can one match strings of blanks?
>
> To even have a chance to do that, you'll have to get hold of a more
> or less precise idea of what "a string of blanks" is. This is work.
>
> Begin with:
>
>   (string-match " +" "A summer full of butterflies")
>   => 1
>
> Bingo: the first run of one-or-more spaces is at the position 1
> (the first position in the string is 0, the "A"). So it's working
> as it should.
>
> So what is /your/ idea of "a string of blank lines" or "a string
> of blanks"? Only you can find out.
>
> If you feel you are stuck in that task, it sometimes help to collect
> a couple of examples and counter-examples (they'll come in handy
> when you try to test your attempts).
>
> Cheers
>  - t
>



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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:19                                 ` steve-humphreys
@ 2021-05-20 11:27                                   ` steve-humphreys
  2021-05-20 12:04                                     ` tomas
  2021-05-20 11:31                                   ` Christopher Dimech
  1 sibling, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 11:27 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

> This is a string of blanks, a string composed of whitespace of any length.
>
> "                     "

The above is what I meant, my gwx mail system is horse manure.


> Sent: Thursday, May 20, 2021 at 11:19 PM
> From: steve-humphreys@gmx.com
> To: tomas@tuxteam.de
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> This is a string of blanks, a string composed of whitespace of any length.
>
> "                     "
>
>
>
> > Sent: Thursday, May 20, 2021 at 10:50 PM
> > From: tomas@tuxteam.de
> > To: steve-humphreys@gmx.com
> > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> >
> > On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:
> >
> > [...]
> >
> > > Done some tests and got some strange results that thought would not match.  Then things
> > > made more sense after your clarification because when I looked at some of the strings,
> > > there was a comma in them.
> >
> > OK. Glad I could help.
> >
> > > Am seeing how to match strings of blank lines
> >
> > What is "a string of blank lines"?
> >
> > I know strings of characters. But a line is not a character.
> >
> > Do you mean "several blank lines next to each other"? I don't
> > think so. But what do you mean?
> >
> > > But " +" does not do the job.
> >
> > Again: you know by now that this will match "one or more spaces". Is
> > that for you a "string of blanks" (huh: where did you leave the
> > "line" from above?) or not?
> >
> > >                  I know why, but how can one match strings of blanks?
> >
> > To even have a chance to do that, you'll have to get hold of a more
> > or less precise idea of what "a string of blanks" is. This is work.
> >
> > Begin with:
> >
> >   (string-match " +" "A summer full of butterflies")
> >   => 1
> >
> > Bingo: the first run of one-or-more spaces is at the position 1
> > (the first position in the string is 0, the "A"). So it's working
> > as it should.
> >
> > So what is /your/ idea of "a string of blank lines" or "a string
> > of blanks"? Only you can find out.
> >
> > If you feel you are stuck in that task, it sometimes help to collect
> > a couple of examples and counter-examples (they'll come in handy
> > when you try to test your attempts).
> >
> > Cheers
> >  - t
> >
>
>



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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:19                                 ` steve-humphreys
  2021-05-20 11:27                                   ` steve-humphreys
@ 2021-05-20 11:31                                   ` Christopher Dimech
  2021-05-20 11:40                                     ` steve-humphreys
                                                       ` (2 more replies)
  1 sibling, 3 replies; 50+ messages in thread
From: Christopher Dimech @ 2021-05-20 11:31 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

This could be what you need

  (string-match "[\s]+ " s)

Matches any white-space character.

> Sent: Thursday, May 20, 2021 at 11:19 PM
> From: steve-humphreys@gmx.com
> To: tomas@tuxteam.de
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> This is a string of blanks, a string composed of whitespace of any length.
>
> "                     "
>
>
>
> > Sent: Thursday, May 20, 2021 at 10:50 PM
> > From: tomas@tuxteam.de
> > To: steve-humphreys@gmx.com
> > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> >
> > On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:
> >
> > [...]
> >
> > > Done some tests and got some strange results that thought would not match.  Then things
> > > made more sense after your clarification because when I looked at some of the strings,
> > > there was a comma in them.
> >
> > OK. Glad I could help.
> >
> > > Am seeing how to match strings of blank lines
> >
> > What is "a string of blank lines"?
> >
> > I know strings of characters. But a line is not a character.
> >
> > Do you mean "several blank lines next to each other"? I don't
> > think so. But what do you mean?
> >
> > > But " +" does not do the job.
> >
> > Again: you know by now that this will match "one or more spaces". Is
> > that for you a "string of blanks" (huh: where did you leave the
> > "line" from above?) or not?
> >
> > >                  I know why, but how can one match strings of blanks?
> >
> > To even have a chance to do that, you'll have to get hold of a more
> > or less precise idea of what "a string of blanks" is. This is work.
> >
> > Begin with:
> >
> >   (string-match " +" "A summer full of butterflies")
> >   => 1
> >
> > Bingo: the first run of one-or-more spaces is at the position 1
> > (the first position in the string is 0, the "A"). So it's working
> > as it should.
> >
> > So what is /your/ idea of "a string of blank lines" or "a string
> > of blanks"? Only you can find out.
> >
> > If you feel you are stuck in that task, it sometimes help to collect
> > a couple of examples and counter-examples (they'll come in handy
> > when you try to test your attempts).
> >
> > Cheers
> >  - t
> >
>
>



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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:31                                   ` Christopher Dimech
@ 2021-05-20 11:40                                     ` steve-humphreys
  2021-05-20 11:49                                       ` Christopher Dimech
  2021-05-20 13:03                                       ` Jean Louis
  2021-05-20 11:59                                     ` tomas
  2021-05-20 12:53                                     ` Jean Louis
  2 siblings, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 11:40 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: help-gnu-emacs@gnu.org



> Sent: Thursday, May 20, 2021 at 11:31 PM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: [External] :  Use the characters "+" and "-" in regular expressions
>
> This could be what you need
>
>   (string-match "[\s]+ " s)
>
> Matches any white-space character.

That would actually match a sentence, which I don't want.

What I like to match is a string composed only of whitespace.

> > Sent: Thursday, May 20, 2021 at 11:19 PM
> > From: steve-humphreys@gmx.com
> > To: tomas@tuxteam.de
> > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> >
> > This is a string of blanks, a string composed of whitespace of any length.
> >
> > "                     "
> >
> >
> >
> > > Sent: Thursday, May 20, 2021 at 10:50 PM
> > > From: tomas@tuxteam.de
> > > To: steve-humphreys@gmx.com
> > > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> > >
> > > On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:
> > >
> > > [...]
> > >
> > > > Done some tests and got some strange results that thought would not match.  Then things
> > > > made more sense after your clarification because when I looked at some of the strings,
> > > > there was a comma in them.
> > >
> > > OK. Glad I could help.
> > >
> > > > Am seeing how to match strings of blank lines
> > >
> > > What is "a string of blank lines"?
> > >
> > > I know strings of characters. But a line is not a character.
> > >
> > > Do you mean "several blank lines next to each other"? I don't
> > > think so. But what do you mean?
> > >
> > > > But " +" does not do the job.
> > >
> > > Again: you know by now that this will match "one or more spaces". Is
> > > that for you a "string of blanks" (huh: where did you leave the
> > > "line" from above?) or not?
> > >
> > > >                  I know why, but how can one match strings of blanks?
> > >
> > > To even have a chance to do that, you'll have to get hold of a more
> > > or less precise idea of what "a string of blanks" is. This is work.
> > >
> > > Begin with:
> > >
> > >   (string-match " +" "A summer full of butterflies")
> > >   => 1
> > >
> > > Bingo: the first run of one-or-more spaces is at the position 1
> > > (the first position in the string is 0, the "A"). So it's working
> > > as it should.
> > >
> > > So what is /your/ idea of "a string of blank lines" or "a string
> > > of blanks"? Only you can find out.
> > >
> > > If you feel you are stuck in that task, it sometimes help to collect
> > > a couple of examples and counter-examples (they'll come in handy
> > > when you try to test your attempts).
> > >
> > > Cheers
> > >  - t
> > >
> >
> >
>
>



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

* [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:40                                     ` steve-humphreys
@ 2021-05-20 11:49                                       ` Christopher Dimech
  2021-05-20 13:03                                       ` Jean Louis
  1 sibling, 0 replies; 50+ messages in thread
From: Christopher Dimech @ 2021-05-20 11:49 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

Try this one instead, which should match strings containing 0 or more whitespace characters.

(string-match "^[\s]*$" s)


> Sent: Thursday, May 20, 2021 at 11:40 PM
> From: steve-humphreys@gmx.com
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: [External] :  Use the characters "+" and "-" in regular expressions
>
>
>
> > Sent: Thursday, May 20, 2021 at 11:31 PM
> > From: "Christopher Dimech" <dimech@gmx.com>
> > To: steve-humphreys@gmx.com
> > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > Subject: [External] :  Use the characters "+" and "-" in regular expressions
> >
> > This could be what you need
> >
> >   (string-match "[\s]+ " s)
> >
> > Matches any white-space character.
>
> That would actually match a sentence, which I don't want.
>
> What I like to match is a string composed only of whitespace.
>
> > > Sent: Thursday, May 20, 2021 at 11:19 PM
> > > From: steve-humphreys@gmx.com
> > > To: tomas@tuxteam.de
> > > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> > >
> > > This is a string of blanks, a string composed of whitespace of any length.
> > >
> > > "                     "
> > >
> > >
> > >
> > > > Sent: Thursday, May 20, 2021 at 10:50 PM
> > > > From: tomas@tuxteam.de
> > > > To: steve-humphreys@gmx.com
> > > > Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> > > > Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
> > > >
> > > > On Thu, May 20, 2021 at 12:37:17PM +0200, steve-humphreys@gmx.com wrote:
> > > >
> > > > [...]
> > > >
> > > > > Done some tests and got some strange results that thought would not match.  Then things
> > > > > made more sense after your clarification because when I looked at some of the strings,
> > > > > there was a comma in them.
> > > >
> > > > OK. Glad I could help.
> > > >
> > > > > Am seeing how to match strings of blank lines
> > > >
> > > > What is "a string of blank lines"?
> > > >
> > > > I know strings of characters. But a line is not a character.
> > > >
> > > > Do you mean "several blank lines next to each other"? I don't
> > > > think so. But what do you mean?
> > > >
> > > > > But " +" does not do the job.
> > > >
> > > > Again: you know by now that this will match "one or more spaces". Is
> > > > that for you a "string of blanks" (huh: where did you leave the
> > > > "line" from above?) or not?
> > > >
> > > > >                  I know why, but how can one match strings of blanks?
> > > >
> > > > To even have a chance to do that, you'll have to get hold of a more
> > > > or less precise idea of what "a string of blanks" is. This is work.
> > > >
> > > > Begin with:
> > > >
> > > >   (string-match " +" "A summer full of butterflies")
> > > >   => 1
> > > >
> > > > Bingo: the first run of one-or-more spaces is at the position 1
> > > > (the first position in the string is 0, the "A"). So it's working
> > > > as it should.
> > > >
> > > > So what is /your/ idea of "a string of blank lines" or "a string
> > > > of blanks"? Only you can find out.
> > > >
> > > > If you feel you are stuck in that task, it sometimes help to collect
> > > > a couple of examples and counter-examples (they'll come in handy
> > > > when you try to test your attempts).
> > > >
> > > > Cheers
> > > >  - t
> > > >
> > >
> > >
> >
> >
>
>



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:31                                   ` Christopher Dimech
  2021-05-20 11:40                                     ` steve-humphreys
@ 2021-05-20 11:59                                     ` tomas
  2021-05-20 12:53                                     ` Jean Louis
  2 siblings, 0 replies; 50+ messages in thread
From: tomas @ 2021-05-20 11:59 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: help-gnu-emacs@gnu.org, steve-humphreys

[-- Attachment #1: Type: text/plain, Size: 658 bytes --]

On Thu, May 20, 2021 at 01:31:22PM +0200, Christopher Dimech wrote:
> This could be what you need
> 
>   (string-match "[\s]+ " s)

You know that you can say " " instead of "\s", right? This is because,
in string literal syntax, "\s" is special and replaced by a space
(analog to "\n", "\r" and friends). This has nothing to do with
regexps: the regexp engine gets to see the " ".

So it's the same as "[ ]+ ".

This is a row of one or more spaces, followed by a space -- which is
the same as a row of two or more spaces, which can be also written
" \\{2\\}" (remember: one backslash for the Lisp string, one for the
regexp).

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:27                                   ` steve-humphreys
@ 2021-05-20 12:04                                     ` tomas
  0 siblings, 0 replies; 50+ messages in thread
From: tomas @ 2021-05-20 12:04 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

On Thu, May 20, 2021 at 01:27:19PM +0200, steve-humphreys@gmx.com wrote:
> > This is a string of blanks, a string composed of whitespace of any length.
> >
> > "                     "
> 
> The above is what I meant, my gwx mail system is horse manure.

Exactly 21 spaces? (I don't think so). Does one space count? Two?

Context: Do you want to find the "   " after the "a" in the following
example: "This is a   sentence with holes"? What about the single " "
after "This"?

Still some thinking for you to do :-)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20  9:42                     ` steve-humphreys
  2021-05-20  9:56                       ` tomas
@ 2021-05-20 12:39                       ` Jean Louis
  1 sibling, 0 replies; 50+ messages in thread
From: Jean Louis @ 2021-05-20 12:39 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 12:43]:
> I have now used ";; [;+-.]+" to match some specific lines.
> 
> (string-match ";; [;+-.]+" s")
> 
> How could I negate the regexp that I have defined?

Why not use not?


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 10:37                             ` steve-humphreys
  2021-05-20 10:50                               ` tomas
@ 2021-05-20 12:46                               ` Jean Louis
  2021-05-20 13:55                                 ` steve-humphreys
  1 sibling, 1 reply; 50+ messages in thread
From: Jean Louis @ 2021-05-20 12:46 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 13:41]:
> Am seeing how to match strings of blank lines
> 
> But " +" does not do the job.  I know why, but how can one match strings of blanks?

[:blank:] is series of characters for that:

(string-match "[[:blank:]]" " ") ⇒ 0

Match new lines as blanks:

(string-match "[[:blank:]]" " 

") ⇒ 0

There can be many various spaces, like EM SPACE: " "

Thus this will not work on EM SPACE:

(string-match " +" " ") ⇒ nil

But this will work:
(string-match "[[:blank:]]" " ") ⇒ 0


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:31                                   ` Christopher Dimech
  2021-05-20 11:40                                     ` steve-humphreys
  2021-05-20 11:59                                     ` tomas
@ 2021-05-20 12:53                                     ` Jean Louis
  2 siblings, 0 replies; 50+ messages in thread
From: Jean Louis @ 2021-05-20 12:53 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: help-gnu-emacs@gnu.org, steve-humphreys

* Christopher Dimech <dimech@gmx.com> [2021-05-20 14:32]:
> This could be what you need
> 
>   (string-match "[\s]+ " s)
> 
> Matches any white-space character.

Why space after plus?

From manual:

"Whitespace characters such as space, tab, newline and formfeed..."

So this does not match new line:

(string-match "[\s]+" "
") ⇒ nil

Neither TAB or FORM FEED:
(string-match "[\s]+" "	") ⇒ nil

(string-match "[\s]+" "\f") ⇒ nil



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 11:40                                     ` steve-humphreys
  2021-05-20 11:49                                       ` Christopher Dimech
@ 2021-05-20 13:03                                       ` Jean Louis
  1 sibling, 0 replies; 50+ messages in thread
From: Jean Louis @ 2021-05-20 13:03 UTC (permalink / raw)
  To: steve-humphreys; +Cc: Christopher Dimech, help-gnu-emacs@gnu.org

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 14:41]:
> >   (string-match "[\s]+ " s)
> >
> > Matches any white-space character.
> 
> That would actually match a sentence, which I don't want.
> 
> What I like to match is a string composed only of whitespace.

Did we not discuss it recently? 

This is how you can make negative match:

(not (string-match "[^[:blank:]]" " ")) ⇒ t

But if there is anything inside that is not blank character, it will
not match:

(not (string-match "[^[:blank:]]" "                j")) ⇒ nil



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 12:46                               ` Jean Louis
@ 2021-05-20 13:55                                 ` steve-humphreys
  2021-05-20 14:14                                   ` Jean Louis
  0 siblings, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 13:55 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs@gnu.org



> Sent: Friday, May 21, 2021 at 12:46 AM
> From: "Jean Louis" <bugs@gnu.support>
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> * steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 13:41]:
> > Am seeing how to match strings of blank lines
> > 
> > But " +" does not do the job.  I know why, but how can one match strings of blanks?
> 
> [:blank:] is series of characters for that:
> 
> (string-match "[[:blank:]]" " ") ⇒ 0

Have done the following  (string-match "^[:blank:]$" s)

Because (string-match "[:blank:]" s) was matching sentences with space between words as well.


> Match new lines as blanks:
> 
> (string-match "[[:blank:]]" " 
> 
> ") ⇒ 0
> 
> There can be many various spaces, like EM SPACE: " "
> 
> Thus this will not work on EM SPACE:
> 
> (string-match " +" " ") ⇒ nil
> 
> But this will work:
> (string-match "[[:blank:]]" " ") ⇒ 0
> 
> 
> -- 
> Jean
> 
> Take action in Free Software Foundation campaigns:
> https://www.fsf.org/campaigns
> 
> Sign an open letter in support of Richard M. Stallman
> https://stallmansupport.org/
> https://rms-support-letter.github.io/
> 
> 
>



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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 13:55                                 ` steve-humphreys
@ 2021-05-20 14:14                                   ` Jean Louis
  2021-05-20 14:28                                     ` steve-humphreys
  0 siblings, 1 reply; 50+ messages in thread
From: Jean Louis @ 2021-05-20 14:14 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 16:56]:

> > [:blank:] is series of characters for that:
> > 
> > (string-match "[[:blank:]]" " ") ⇒ 0
> 
> Have done the following  (string-match "^[:blank:]$" " ")
> 
> Because (string-match "[:blank:]" s) was matching sentences with
> space between words as well.

Are you sure? As in that case the meaning of ^ is that it matches
begin of line, while in [^[:blank:]] it match anything but non-blank
and meaning of ^ is "not match" in that case.



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 14:14                                   ` Jean Louis
@ 2021-05-20 14:28                                     ` steve-humphreys
  2021-05-20 16:24                                       ` Yuri Khan
  2021-05-21  5:48                                       ` Jean Louis
  0 siblings, 2 replies; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 14:28 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs@gnu.org



> Sent: Friday, May 21, 2021 at 2:14 AM
> From: "Jean Louis" <bugs@gnu.support>
> To: steve-humphreys@gmx.com
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] :  Use the characters "+" and "-" in regular expressions
>
> * steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 16:56]:
> 
> > > [:blank:] is series of characters for that:
> > > 
> > > (string-match "[[:blank:]]" " ") ⇒ 0
> > 
> > Have done the following  (string-match "^[:blank:]$" " ")
> > 
> > Because (string-match "[:blank:]" s) was matching sentences with
> > space between words as well.
> 
> Are you sure? As in that case the meaning of ^ is that it matches
> begin of line, while in [^[:blank:]] it match anything but non-blank
> and meaning of ^ is "not match" in that case.

I have settled with

  (string-match "^[:blank:]*$" s)

This would match only strings with spaces, not sentences with spaces.  What do you think?


 
> 
> -- 
> Jean
> 
> Take action in Free Software Foundation campaigns:
> https://www.fsf.org/campaigns
> 
> Sign an open letter in support of Richard M. Stallman
> https://stallmansupport.org/
> https://rms-support-letter.github.io/
> 
> 
>



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

* Re: [External] : Use the characters "+" and "-" in regular expressions
  2021-05-20 14:28                                     ` steve-humphreys
@ 2021-05-20 16:24                                       ` Yuri Khan
  2021-05-20 16:34                                         ` steve-humphreys
  2021-05-21  5:48                                       ` Jean Louis
  1 sibling, 1 reply; 50+ messages in thread
From: Yuri Khan @ 2021-05-20 16:24 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org, Jean Louis

On Thu, 20 May 2021 at 21:50, <steve-humphreys@gmx.com> wrote:

> I have settled with
>
>   (string-match "^[:blank:]*$" s)
>
> This would match only strings with spaces, not sentences with spaces.  What do you think?

No, that will match lines consisting of colons and letters a, b, k, l,
and n. To use a named character class, you need double brackets.



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

* [External] : Use the characters "+" and "-" in regular expressions
  2021-05-20 16:24                                       ` Yuri Khan
@ 2021-05-20 16:34                                         ` steve-humphreys
  2021-05-20 17:16                                           ` Eduardo Ochs
  0 siblings, 1 reply; 50+ messages in thread
From: steve-humphreys @ 2021-05-20 16:34 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs@gnu.org, Jean Louis



> Sent: Friday, May 21, 2021 at 4:24 AM
> From: "Yuri Khan" <yuri.v.khan@gmail.com>
> To: steve-humphreys@gmx.com
> Cc: "Jean Louis" <bugs@gnu.support>, "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Subject: Re: [External] : Use the characters "+" and "-" in regular expressions
>
> On Thu, 20 May 2021 at 21:50, <steve-humphreys@gmx.com> wrote:
>
> > I have settled with
> >
> >   (string-match "^[:blank:]*$" s)
> >
> > This would match only strings with spaces, not sentences with spaces.  What do you think?
>
> No, that will match lines consisting of colons and letters a, b, k, l,
> and n. To use a named character class, you need double brackets.

Like this then

(string-match "^[[:blank:]]*$" s)




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

* Re: [External] : Use the characters "+" and "-" in regular expressions
  2021-05-20 16:34                                         ` steve-humphreys
@ 2021-05-20 17:16                                           ` Eduardo Ochs
  2021-05-20 18:29                                             ` Drew Adams
  0 siblings, 1 reply; 50+ messages in thread
From: Eduardo Ochs @ 2021-05-20 17:16 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org, Jean Louis, Yuri Khan

Btw, my favorite way to not have to remember all these, ahem, corner
cases, is to put comments like these near my uglier sexps:

;; (info "(elisp)Rx Constructs")
;; (rx (any "[]") (one-or-more "=") (any "[]"))

On Thu, 20 May 2021 at 13:35, <steve-humphreys@gmx.com> wrote:
> ...



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

* RE: [External] : Use the characters "+" and "-" in regular expressions
  2021-05-20 17:16                                           ` Eduardo Ochs
@ 2021-05-20 18:29                                             ` Drew Adams
  0 siblings, 0 replies; 50+ messages in thread
From: Drew Adams @ 2021-05-20 18:29 UTC (permalink / raw)
  To: Eduardo Ochs, steve-humphreys@gmx.com
  Cc: help-gnu-emacs@gnu.org, Jean Louis, Yuri Khan

> Btw, my favorite way to not have to remember all these, ahem, corner
> cases, is to put comments like these near my uglier sexps:
> 
> ;; (info "(elisp)Rx Constructs")
> ;; (rx (any "[]") (one-or-more "=") (any "[]"))

I do the same (e.g., the latter comment).

IOW, I use RX to double-check or sometimes to create a regexp.

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

* Re: [External] :  Use the characters "+" and "-" in regular expressions
  2021-05-20 14:28                                     ` steve-humphreys
  2021-05-20 16:24                                       ` Yuri Khan
@ 2021-05-21  5:48                                       ` Jean Louis
  1 sibling, 0 replies; 50+ messages in thread
From: Jean Louis @ 2021-05-21  5:48 UTC (permalink / raw)
  To: steve-humphreys; +Cc: help-gnu-emacs@gnu.org

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2021-05-20 17:28]:
> I have settled with
> 
>   (string-match "^[:blank:]*$" s)
> 
> This would match only strings with spaces, not sentences with
> spaces.  What do you think?

That one is good to match nothing:

(string-match "^[:blank:]*$" "") ⇒ 0

(string-match "^[:blank:]*$" " ") ⇒ nil

(string-match "^[:blank:]*$" "  ") ⇒ nil

You have to read the manual: (info "(elisp) Regular Expressions")

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




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

end of thread, other threads:[~2021-05-21  5:48 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-19 16:07 Use the characters "+" and "-" in regular expressions steve-humphreys
2021-05-19 16:17 ` Skip Montanaro
2021-05-19 16:26   ` steve-humphreys
2021-05-19 16:47     ` Yuri Khan
2021-05-19 17:39       ` steve-humphreys
2021-05-19 19:16         ` tomas
2021-05-19 19:27           ` tomas
2021-05-19 19:30         ` Yuri Khan
2021-05-19 21:32           ` tomas
2021-05-19 21:59             ` [External] : " Drew Adams
2021-05-20  6:26               ` RE: [External] : " steve-humphreys
2021-05-20  7:59                 ` steve-humphreys
2021-05-20  8:26                   ` tomas
2021-05-20  8:41                     ` steve-humphreys
2021-05-20  9:42                     ` steve-humphreys
2021-05-20  9:56                       ` tomas
2021-05-20 10:11                         ` steve-humphreys
2021-05-20 10:22                           ` tomas
2021-05-20 10:37                             ` steve-humphreys
2021-05-20 10:50                               ` tomas
2021-05-20 11:19                                 ` steve-humphreys
2021-05-20 11:27                                   ` steve-humphreys
2021-05-20 12:04                                     ` tomas
2021-05-20 11:31                                   ` Christopher Dimech
2021-05-20 11:40                                     ` steve-humphreys
2021-05-20 11:49                                       ` Christopher Dimech
2021-05-20 13:03                                       ` Jean Louis
2021-05-20 11:59                                     ` tomas
2021-05-20 12:53                                     ` Jean Louis
2021-05-20 12:46                               ` Jean Louis
2021-05-20 13:55                                 ` steve-humphreys
2021-05-20 14:14                                   ` Jean Louis
2021-05-20 14:28                                     ` steve-humphreys
2021-05-20 16:24                                       ` Yuri Khan
2021-05-20 16:34                                         ` steve-humphreys
2021-05-20 17:16                                           ` Eduardo Ochs
2021-05-20 18:29                                             ` Drew Adams
2021-05-21  5:48                                       ` Jean Louis
2021-05-20 10:29                         ` Negating a regexp Yuri Khan
2021-05-20 10:39                           ` tomas
2021-05-20 12:39                       ` [External] : Use the characters "+" and "-" in regular expressions Jean Louis
2021-05-20  7:15               ` Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions] tomas
2021-05-20  8:08                 ` Robert Pluim
2021-05-19 19:26       ` [External] : Re: Use the characters "+" and "-" in regular expressions Drew Adams
2021-05-19 19:25     ` Drew Adams
2021-05-19 16:27   ` tomas
2021-05-19 16:39     ` Skip Montanaro
2021-05-19 17:43       ` Marcin Borkowski
2021-05-19 19:10       ` tomas
2021-05-19 19:17 ` [External] : " Drew Adams

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.