From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Regular expressions and user-escaped characters Date: Mon, 02 Dec 2024 23:32:46 +0100 Message-ID: <864j3lyaup.fsf@fastmail.fm> References: <87plm9g2rm.fsf@librehacker.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23796"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.12.7; emacs 29.4 Cc: Help Gnu Emacs Mailing List To: Christopher Howard Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 02 23:33:47 2024 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 1tIEzA-0005zt-Pb for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 02 Dec 2024 23:33:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEyN-0006l1-Jv; Mon, 02 Dec 2024 17:32:55 -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 1tIEyM-0006kc-7z for help-gnu-emacs@gnu.org; Mon, 02 Dec 2024 17:32:54 -0500 Original-Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEyK-0004HJ-Ei for help-gnu-emacs@gnu.org; Mon, 02 Dec 2024 17:32:53 -0500 Original-Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id CAA601140170; Mon, 2 Dec 2024 17:32:49 -0500 (EST) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Mon, 02 Dec 2024 17:32:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1733178769; x=1733265169; bh=y5VdT9vxvA R8WoDvr3UdwY8Spzy7WlMMEHFB9r58SwI=; b=d43hzgcCsxRv9TUMJod28tHUku b9oJoadoe7YiSGT6xga+i4l4A/9OXMKqh5vAK8LPWVT1B69ESrWG5LfnyKE0ngc/ 20lgGesyh6e+1WD4VZAs/Z1RQ54Xhhhe6PAlCJ5v8AT5nk9s7jGNLsx3+H0iBiXQ 1OZ028D0k2IRKBvvYTyoYrQAreM4czg64qmKvnFfSXvMgEiF15i+uwWfvZK6s3h+ EQ1MHQRWl18b8ToSfAubB1zDOSc+4xjmXPJV1qRLbobMAcaOCQ1Oa35ussYQzI1H ASrxfXs4iqqrv8Q3KKzS96JQGUXTwehgIfNM8v6uvkCDDGeCulQhzRNvZWzw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733178769; x=1733265169; bh=y5VdT9vxvAR8WoDvr3UdwY8Spzy7WlMMEHF B9r58SwI=; b=elytElycEO3EVJI//gnulz0RKSwuyPd170gQUdE12S+QcqYE75Z rgKvjltfNxM1M9EyK3VsxhLJfkxM2JGdVXlFk47PTIrOKGThBtM71XgBH/58MWmr vBBww3MrH3l8Sezlc50UqL6uALlz2GZoUpGLwJkIS5Ke3naH7w4brxch3BD50Vrs DzWkQBhLMfmOca3bbraug7lYdnfTS4NZ7CB+I8vcY9ZwGcq7Zs/VwZf7ona0CSPU JyUoF9i+tUNMjboxGTXDkW4G4A+mZ88N04y8Y2OVk3FfHJ/5rgHu3SMuuyw7b6Qc JcvzyBG3rp2/EY3J4EyJcN7G4B4RyICs4sA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheelgdduiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefujghffgffkfggtgesthdtredttdertden ucfhrhhomheplfhoohhsthcumfhrvghmvghrshcuoehjohhoshhtkhhrvghmvghrshesfh grshhtmhgrihhlrdhfmheqnecuggftrfgrthhtvghrnhepfeekjefgffdtgfffjeduueek teehudfhveethffhheeihfeltdfghfegkeeivdehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepjhhoohhsthhkrhgvmhgvrhhssehfrghsthhm rghilhdrfhhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtph htthhopehhvghlphdqghhnuhdqvghmrggtshesghhnuhdrohhrghdprhgtphhtthhopegt hhhrihhsthhophhhvghrsehlihgsrhgvhhgrtghkvghrrdgtohhm X-ME-Proxy: Feedback-ID: ie15541ac:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Dec 2024 17:32:48 -0500 (EST) In-Reply-To: <87plm9g2rm.fsf@librehacker.com> (Christopher Howard's message of "Mon, 02 Dec 2024 13:04:45 -0900") Received-SPF: pass client-ip=103.168.172.152; envelope-from=joostkremers@fastmail.fm; helo=fhigh-a1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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:148515 Archived-At: On Mon, Dec 02 2024, Christopher Howard wrote: > Hi, what do you do in a regular expression if you want to match a > character, but not a the same character that has been escaped by the user. > E.g., if I want my regular expression to look for ?\[ (ASCII 91), matching > string "[" and "a[a" but not string "\\[" or "a\\[a", if you follow me. Is > this possible with just a regular expression? You may get away with something like "[^\\][[]", though keep in mind that that does not match a ?[ not preceded by a backslash, but rather a ?[ preceded by a character that is not a backslash. Depending on your use case, that might suffice, though, esp. if you use a capturing group: ``` (let ((str "a[a")) (when (string-match "[^\\]\\([[]\\)" str) (match-string 1 str))) => "[" ``` vs.: ``` (let ((str "a\\[a")) (when (string-match "[^\\]\\([[]\\)" str) (match-string 1 str))) => nil ``` The "proper" way to do this would be to use negative lookbehind, `"(? If not, what is a good workaround? I was wondering about, say, replacing > all the escaped characters first with some uncommon character (like a > control code) and then converting back afterwards. But then I suppose I > would need to do a check for that uncommon character first. That would probably work. -- Joost Kremers Life has its moments