unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: tpeplt <tpeplt@gmail.com>
To: Bruno Barbier <brubar.cs@gmail.com>
Cc: Heime <heimeborgia@protonmail.com>,
	 Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Matching labels with buttons
Date: Mon, 15 Jul 2024 14:29:33 -0400	[thread overview]
Message-ID: <877cdm1pbm.fsf@gmail.com> (raw)
In-Reply-To: <66950ec4.df0a0220.b86df.5c24@mx.google.com> (Bruno Barbier's message of "Mon, 15 Jul 2024 13:57:55 +0200")

Bruno Barbier <brubar.cs@gmail.com> writes:

> Heime <heimeborgia@protonmail.com> writes:
>
> ...
>
> Because it does match:
>
>    (string-match "\\(\\s-*\\[\\-\\]\\s-*\\)\\(.*\\)" "OFF [-]")
>    => 3
>
> When building regular expressions, I'm often using the amazing M-x
> re-builder: it allows to construct regexps interactively with visual
> feedbacks, it even understands the "rx" syntax, for more readable
> regexps.
>

Seconded.  Build your regular expression using the regular-expression
builder, ‘re-builder’.  See (info "(elisp) Regular Expressions").  Note
that ‘re-builder’ comes with a menu that you can use either to carry out
re-builder commands or to learn the re-builder key sequences for
commands.

An approach you can try:

1. Create a text file (or a only a buffer) that contains examples of
strings that you want your regular expression to match.  Start with the
simplest example and build up line-by-line with additional examples to
the most complex example that you can think of.

2. Start re-builder with M-x re-builder.  Enter the simplest regular
expression that should match your simplest example.  Read the Elisp
manual entry above, if necessary, to resolve any misunderstanding if
your regular expression does not match.  Once the simplest regular
expression matches your simplest example, add to your regular expression
in order to match the second example.  The new expression should match
your first and second example before you move to matching your third
example.  And so on.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.



      reply	other threads:[~2024-07-15 18:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 11:17 Matching labels with buttons Heime
2024-07-15 11:25 ` Heime
2024-07-15 11:56   ` Stephen Berman
2024-07-15 12:35     ` Heime
2024-07-15 12:52       ` Stephen Berman
2024-07-15 12:58         ` Heime
2024-07-15 13:42           ` Stephen Berman
2024-07-15 16:24             ` Heime
2024-07-15 17:25               ` Heime
2024-07-15 21:20                 ` Stephen Berman
2024-07-15 21:29                   ` Heime
2024-07-15 21:50                     ` Stephen Berman
2024-07-15 22:29                       ` Heime
2024-07-15 22:46                         ` Stephen Berman
2024-07-15 23:02                           ` Heime
2024-07-15 11:57   ` Bruno Barbier
2024-07-15 18:29     ` tpeplt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cdm1pbm.fsf@gmail.com \
    --to=tpeplt@gmail.com \
    --cc=brubar.cs@gmail.com \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).