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

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

Re: Matching labels with buttons


From: tpeplt
Subject: Re: Matching labels with buttons
Date: Mon, 15 Jul 2024 14:29:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

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