From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: how to use a variable inside Emacs regex features ? Date: Thu, 23 May 2019 08:53:08 +0200 Message-ID: <20190523065308.GA28035@tuxteam.de> References: <7bb10774-01c5-402c-9924-1e7c23f32358@default> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9amGYk9869ThD9tj" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="35963"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 23 08:53:34 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hThbZ-0009Eo-Ti for geh-help-gnu-emacs@m.gmane.org; Thu, 23 May 2019 08:53:34 +0200 Original-Received: from localhost ([127.0.0.1]:58841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hThbY-0002n1-JE for geh-help-gnu-emacs@m.gmane.org; Thu, 23 May 2019 02:53:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:55897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hThbO-0002mi-GA for help-gnu-emacs@gnu.org; Thu, 23 May 2019 02:53:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hThbM-0001E1-As for help-gnu-emacs@gnu.org; Thu, 23 May 2019 02:53:22 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:44564) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hThbL-00019F-SP for help-gnu-emacs@gnu.org; Thu, 23 May 2019 02:53:20 -0400 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:To:Date; bh=ONB9ZfYN8kRNP414Hy5LzzIx9Ja7yCuZGDBvyBrmAhA=; b=OZi5i1WwD82larQqiwf+qDNG6q9j3KO/6Uapbak8OV8L4oqPpBt/PqSk8/3E/CSpBNcNojs/GetSGyxcFTi5AdXipy5HpFMu56TMW80MnbnjhEDZ2/0+b+MG39ftQkLHD8C732QFUeTiY1QTP7sUR55rMDkxACqyDgzHPj4W4m11qsJMQQ24QHZXdOSnQWKjClhS6EISv1zO4jKQRiIhR2nJFBWb1Dw1MH3UIAq3JCdEy6jZvBTG43pFT/UBpO4EelI5BtyTSckyK2gdQeYXkA69bwm37xNGTlIqcDz4UbOyNFiV2UeAg/73oxYJFfkfotLUqrbdNCGZZkRZ+dqglA==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1hThbA-0007Rp-EH for help-gnu-emacs@gnu.org; Thu, 23 May 2019 08:53:08 +0200 Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120573 Archived-At: --9amGYk9869ThD9tj Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 23, 2019 at 11:46:29AM +0700, Budi wrote: > (setq ntimes 7) > re-search-forward "hello\\{ntimes\\}" >=20 > How is above supposed to work ? It's not supposed to work ;-) (the specific construct above takes a constant between \{ and \}). Usually you construct your string using whatever other facilities Elisp has, e.g. (let* ((ntimes 17) (re (format "fo\\{%d\\}" ntimes))) (re-search-forward re)) ; searches for 'f' followed by 17 'o's Be extra careful for variables containing regular expression special characters (in the above case of an int, there is no danger). Use the function 'regexp-quote' as needed. If you are doing more complex things, you might like 'rx', which allows you to write regular expressions in S-expression syntax, thus giving you access to template macros and all that goodness. Cheers -- t --9amGYk9869ThD9tj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlzmQ1QACgkQBcgs9XrR2kYs9gCeJT7VzOAPI+rn++GAUC3H9nr/ 87oAnib9SGYZqc/bu9Wu29I9H8v14KTk =ngLK -----END PGP SIGNATURE----- --9amGYk9869ThD9tj--