On Sat, Jun 29, 2024 at 06:37:23AM -0500, Richard Owlett wrote:

[...]

> When searching for information on regular expressions I came across one that
> did it by searching for
>    {"1 thru 9" OR "10 thru 99" OR "100 thru 999"} .
> I lost the reference ;<

That would be something like ([0-9]|[1-9][0-9]|[1-9][0-9][0-9])
since [x-y] expresses a range of characters, the | does OR and
the () do grouping [1].

If you allow yourself to be a bit sloppy [2], and allow numbers
with leading zeros, many regexps flavors have the "limited count
operator" {min,max}, with which you might say [0-9]{1,3} (you
won't need the grouping here, since the repeat operator binds
strongly enough to not mess up the rest of your regexp.

CAVEAT IMPLEMENTOR: Depending on the flavor of your regexps, the
() and sometimes the | need a backslash in front to give them
their magic meaning. In Emacs they do, in Perl (and PCRE, which
is most probably the engine behind Pluma) they don't. In grep
(and sed) you can switch behavior with an option (-E was it,
IIRC).

Cheers

[1] This grouping is (again, depening on your regexp flavour)
   a "capturing grouping", meaning that you can refer later
   to what was matched by the sub-expression in the parens.
   There are also (flavor blah blah) non-capturing groupings.

[2] You always are somewhat sloppy with regexps. Actually you
   are being sloppy already, since every classical textbook
   will tell you that they totally suck at understanding
   "nested stuff", which HTML is, alas. But under the right
   conditions they can butcher it alright :-)

-- 
tomás

Attachment: signature.asc
Description: PGP signature

Reply via email to