From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Help improve regular expression for 24 hours format Date: Thu, 24 Nov 2022 10:38:27 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SfD78s46JKvF79xx" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22418"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuri Khan To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 24 10:39:19 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy8hT-0005bF-9d for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 10:39:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oy8gq-0006YF-Vc; Thu, 24 Nov 2022 04:38:40 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy8gj-0006Xn-Jb for help-gnu-emacs@gnu.org; Thu, 24 Nov 2022 04:38:37 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy8gg-0003lA-Gg for help-gnu-emacs@gnu.org; Thu, 24 Nov 2022 04:38:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6qtuaQJVmsNl/MoCyFr5lx9HRBqMWkq4xWVWLXu2vh0=; b=tv4RjTm8hcm40SU3tCUN88fySR QYwVtMt2I1JP0259sMa2FKQr6cg/J6ZckL2RjW28H0z2Y4wmFFQSZ2sPCMV5VRfJEBM8HMxV1Qtyn O+DjqF5RmPlg7DE9s0tkjsiG+VT550sA1Hv4FqmQGL3t+t0zRCxnXeZX8HSvfwtbrmkIQsSPq2iHg xXbXLK63WsFEbSY4jsK3Mx2RYB0Q4CU4jg4rHEjORdO97mvcOzZbn8OEJFK5vh9tKL3HpPB+MGuIL o1W1GvIzscFobdT2U4Kn2RcDVNZu9I1q5ktyZKXta9uCv4g/PTUQt9WFAxo8wJzVv6jnKsq2GQxUW cVoEqsxA==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1oy8gd-0007nG-LA; Thu, 24 Nov 2022 10:38:27 +0100 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141128 Archived-At: --SfD78s46JKvF79xx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 24, 2022 at 11:59:20AM +0300, Jean Louis wrote: > * Yuri Khan [2022-11-24 09:33]: > > On Thu, 24 Nov 2022 at 10:38, Jean Louis wrote: > >=20 > > > This regular expression shall match 24 hours format such as "12:34". > > > > > > I do not like how I wrote this regular expression, is there way to > > > provide to `rx' function something like "[012]"? > >=20 > > I=E2=80=99d write it in classic regexp notation as > >=20 > > \(?:\(?:[01][0-9]|2[0-3]\):\(?:[0-5][0-9]\)\) > >=20 > > and probably leave like that as it=E2=80=99s readable enough as is. > >=20 > > If you feel the need for rx here, then, as Tomas said, =E2=80=98any=E2= =80=99 (aka =E2=80=98in=E2=80=99 > > and =E2=80=98char=E2=80=99) with ranges is your friend. > >=20 > > (Also I don=E2=80=99t understand your use of =E2=80=98(=3D 1 =E2=80=A6)= =E2=80=99. Looks redundant to > > me.) >=20 > Thanks, I make it now this way: >=20 > (defvar rcd-rx-time (rx line-start (or "00" "01" "02" "03" "04" "05" "06"= "07" "08" "09" "10" "11"=20 > "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23") > ":" (any "0" "1" "2" "3" "4" "5") (any digit) > line-end) > "Regular expression for 24 hours format") Hm. By distributive law, (or (seq (any "01") (any digit)) (seq "2" (any "03= "))) should cover your hours part. And for the minutes's first digit, remember t= hat `any' can do ranges: (any "0-5") resp. (any (?0 . ?5)) > =E2=9E=9C "^\\(?:0[0-9]\\|1[0-9]\\|2[0-3]\\):[0-5][[:digit:]]$" Even taking inspiration on what the "compiler" did of your expression might lead you to a simpler (and more readable!) expression, e.g. (or (seq "0" (any digit)) (seq "1" (any digit)) (seq "2" (any "0-3"))) although slightly longer than my first proposal (perhaps the second is "quicker", but I'd let the regexp compiler sort that out: you are optimising for the human reader, after all). Cheers --=20 t --SfD78s46JKvF79xx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCY387jAAKCRAFyCz1etHa RnrYAJ9KKJ2D9fsM06q7JF+k/3cMa7vQ9ACeMgesLyCxh76ZFx2KBp6vLo/cnos= =dVS5 -----END PGP SIGNATURE----- --SfD78s46JKvF79xx--