From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Forrest Newsgroups: gmane.emacs.help Subject: Re: Reg-exp Date: Thu, 22 Aug 2002 17:59:47 -0400 (EDT) Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: main.gmane.org 1030053603 20733 127.0.0.1 (22 Aug 2002 22:00:03 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 22 Aug 2002 22:00:03 +0000 (UTC) Cc: Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17hzzk-0005OI-00 for ; Fri, 23 Aug 2002 00:00:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17i00r-0002OH-00; Thu, 22 Aug 2002 18:01:09 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17i00Z-0002Mc-00 for help-gnu-emacs@gnu.org; Thu, 22 Aug 2002 18:00:51 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17i00X-0002MN-00 for help-gnu-emacs@gnu.org; Thu, 22 Aug 2002 18:00:51 -0400 Original-Received: from mug.sys.virginia.edu ([128.143.6.251]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17i00X-0002MI-00 for help-gnu-emacs@gnu.org; Thu, 22 Aug 2002 18:00:49 -0400 Original-Received: from localhost (drf5n@localhost) by mug.sys.virginia.edu (8.11.4/8.11.4) with ESMTP id g7MLxlB06869; Thu, 22 Aug 2002 17:59:47 -0400 Original-To: "J. Thomas" In-Reply-To: Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:860 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:860 On Thu, 22 Aug 2002, J. Thomas wrote: > > I'm interested in doing a query search and replace for a regular > expression that goes something like this: > > 1. find a particular string (e.g. "test") followed by any 3 random > > characters or numbers (e.g. "test100", "test234", "test_al") > > 2. replace an occurence with the random 3 characters/numbers followed by > > "test" (e.g. "100test", "234test", "_altest). I would try: M-x query-replace-regexp \(test\)\([0-9a-zA-Z_]+\) \2\1 the \( \) pair defines groups which are refered to as \1 and \2 in the replacement. This doesn't do the exact 3 that you want, but I don't know if emacs has a bounding operator like {3} or {2,4} so if the 'one or more' operator '+' wont do what you want, you could do the repeat manually: \(test\)\([0-9a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]\) > > > How would I go about doing this? > > Thanks, > jt > > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > Jason Thomas > Graduate Student > Dept. of Sociology > University of Washington, Seattle > method@u.washington.edu > http://students.washington.edu/~method > > > > > _______________________________________________ > Help-gnu-emacs mailing list > Help-gnu-emacs@gnu.org > http://mail.gnu.org/mailman/listinfo/help-gnu-emacs > -- Dave Forrest drf5n@virginia.edu (804)642-0662h (434)924-3954w http://mug.sys.virginia.edu/~drf5n/