unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Trouble with regexp
@ 2005-10-25 16:24 exits funnel
  0 siblings, 0 replies; 10+ messages in thread
From: exits funnel @ 2005-10-25 16:24 UTC (permalink / raw)


Hello,

I have a text file with hundres of lines of the form:

%token FOO_Alter

where 'FOO' is always 'FOO' but 'Alter' is variable. 
I'd like to convert these lines to:

  t_foo_Alter = 'Alter';

using query-replace-regexp but I can't quite get it
right.  Here's what I have so far:

M-x query-replace-regexp RET
%token XTAG_\(a-Z\) RET
  t_xtag_\1 = '\1'; RET

Sadly, I get 0 occurences replaced.  Can anyone set me
straight?  Thanks in advance.

-exits

  


		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
       [not found] <mailman.12639.1130257485.20277.help-gnu-emacs@gnu.org>
@ 2005-10-25 17:16 ` rgb
  2005-10-25 17:38   ` exits funnel
  2005-10-25 17:54   ` Pascal Bourguignon
  2005-10-25 17:17 ` Chris McMahan
  1 sibling, 2 replies; 10+ messages in thread
From: rgb @ 2005-10-25 17:16 UTC (permalink / raw)


> %token FOO_Alter
>
> where 'FOO' is always 'FOO' but 'Alter' is variable.
> I'd like to convert these lines to:
>
>   t_foo_Alter = 'Alter';

Does this work?

%token FOO_\([a-zA-Z]+\)
t_foo_\1 = '\1';

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
       [not found] <mailman.12639.1130257485.20277.help-gnu-emacs@gnu.org>
  2005-10-25 17:16 ` Trouble with regexp rgb
@ 2005-10-25 17:17 ` Chris McMahan
  1 sibling, 0 replies; 10+ messages in thread
From: Chris McMahan @ 2005-10-25 17:17 UTC (permalink / raw)


I would recommend that you use a macro instead of a regexp, if for no
other reason than I don't know the regexp to use :)


exits funnel <exitsfunnel@yahoo.com> writes:
> Hello,
>
> I have a text file with hundres of lines of the form:
>
> %token FOO_Alter
>
> where 'FOO' is always 'FOO' but 'Alter' is variable. 
> I'd like to convert these lines to:
>
>   t_foo_Alter = 'Alter';
>
> using query-replace-regexp but I can't quite get it
> right.  Here's what I have so far:
>
> M-x query-replace-regexp RET
> %token XTAG_\(a-Z\) RET
>   t_xtag_\1 = '\1'; RET
>
> Sadly, I get 0 occurences replaced.  Can anyone set me
> straight?  Thanks in advance.
>
> -exits

-- 
     (.   .)
  =ooO=(_)=Ooo=====================================
  Chris McMahan | first_initiallastname@one.dot.net
  =================================================

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
  2005-10-25 17:16 ` Trouble with regexp rgb
@ 2005-10-25 17:38   ` exits funnel
  2005-10-25 17:54   ` Pascal Bourguignon
  1 sibling, 0 replies; 10+ messages in thread
From: exits funnel @ 2005-10-25 17:38 UTC (permalink / raw)


> > %token FOO_Alter
> >
> > where 'FOO' is always 'FOO' but 'Alter' is
> variable.
> > I'd like to convert these lines to:
> >
> >   t_foo_Alter = 'Alter';
> 
> Does this work?

Like a charm.  Thanks!

-exits


		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
  2005-10-25 17:16 ` Trouble with regexp rgb
  2005-10-25 17:38   ` exits funnel
@ 2005-10-25 17:54   ` Pascal Bourguignon
  2005-10-25 18:40     ` exits funnel
  1 sibling, 1 reply; 10+ messages in thread
From: Pascal Bourguignon @ 2005-10-25 17:54 UTC (permalink / raw)


"rgb" <rbielaws@i1.net> writes:

>> %token FOO_Alter
>>
>> where 'FOO' is always 'FOO' but 'Alter' is variable.
>> I'd like to convert these lines to:
>>
>>   t_foo_Alter = 'Alter';
>
> Does this work?
>
> %token FOO_\([a-zA-Z]+\)
> t_foo_\1 = '\1';

Given the input file, I'd wouldn't bother matching the exact
characters (you could have digits and underlines) and use:
 
%token FOO_\([^ ]*\)
t_foo_\1 = '\1';

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Cats meow out of angst
"Thumbs! If only we had thumbs!
We could break so much!"

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
  2005-10-25 17:54   ` Pascal Bourguignon
@ 2005-10-25 18:40     ` exits funnel
  0 siblings, 0 replies; 10+ messages in thread
From: exits funnel @ 2005-10-25 18:40 UTC (permalink / raw)




--- Pascal Bourguignon <spam@mouse-potato.com> wrote:
> Given the input file, I'd wouldn't bother matching
> the exact
> characters (you could have digits and underlines)
> and use:
>  
> %token FOO_\([^ ]*\)
> t_foo_\1 = '\1';

Thanks Pascal, that was even better as I did in fact
run into some '_'s;

-exits


	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Trouble with regexp
@ 2008-05-22 16:00 TheLonelyStar
  2008-05-22 16:47 ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: TheLonelyStar @ 2008-05-22 16:00 UTC (permalink / raw)
  To: Help-gnu-emacs


Hi,

I some trouble with regular expression. I thought, the regexp "\(foo\|bar\)"
should match either foo and bar.
But  if I have a buffer with "foo" in it, the regexp build does not match it
with that :(.

Thanks!
Nathan
-- 
View this message in context: http://www.nabble.com/Trouble-with-regexp-tp17407478p17407478.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
       [not found] <mailman.12018.1211472045.18990.help-gnu-emacs@gnu.org>
@ 2008-05-22 16:31 ` David Kastrup
  0 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2008-05-22 16:31 UTC (permalink / raw)
  To: help-gnu-emacs

TheLonelyStar <nabble@lonely-star.org> writes:

> Hi,
>
> I some trouble with regular expression. I thought, the regexp "\(foo\|bar\)"
> should match either foo and bar.
> But  if I have a buffer with "foo" in it, the regexp build does not match it
> with that :(.

It does here.  You are probably not doing the right quoting.  Please
remember that the Lisp string syntax requires quoting of quote marks and
backslashes on _top_ of what quoting your regexps will need.

So please post the actual code that fails instead of talking about it.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
  2008-05-22 16:00 TheLonelyStar
@ 2008-05-22 16:47 ` Alan Mackenzie
  2008-05-22 17:27   ` Joel J. Adamson
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2008-05-22 16:47 UTC (permalink / raw)
  To: TheLonelyStar; +Cc: Help-gnu-emacs


Hi, TLS!

On Thu, 22 May 2008, TheLonelyStar wrote:


> Hi,

> I some trouble with regular expression. I thought, the regexp "\(foo\|bar\)"
> should match either foo and bar.
> But  if I have a buffer with "foo" in it, the regexp build does not match it
> with that :(.

Are you sure your regexp is what you think it is?  If you are typing it 
into an elisp program, you need to write:

     "\\(foo\\|bar\\)"

.  If you've done C-M-s and are typing into the minibuffer, you don't 
double the quotes.

> Thanks!
> Nathan

-- 
Alan Mackenzie (Nuremberg, Germany).




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Trouble with regexp
  2008-05-22 16:47 ` Alan Mackenzie
@ 2008-05-22 17:27   ` Joel J. Adamson
  0 siblings, 0 replies; 10+ messages in thread
From: Joel J. Adamson @ 2008-05-22 17:27 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Help-gnu-emacs

Alan Mackenzie <acm@muc.de> writes:

> Hi, TLS!
>
> On Thu, 22 May 2008, TheLonelyStar wrote:
>
>
>> Hi,
>
>> I some trouble with regular expression. I thought, the regexp "\(foo\|bar\)"
>> should match either foo and bar.
>> But  if I have a buffer with "foo" in it, the regexp build does not match it
>> with that :(.
>
> Are you sure your regexp is what you think it is?  If you are typing
> it into an elisp program, you need to write:
>
>     "\\(foo\\|bar\\)"
>
> .  If you've done C-M-s and are typing into the minibuffer, you don't
> double the quotes.

I think the problem is he's using re-builder, and expecting it to work
the same as regexp Isearch.  If I enter this

"\\(some\\|with\\|regexp\\)"

in re-builder, then I get some matches.  Without the double backslashes
and quoting, it won't match.

But in Regexp Isearch

\(some\|with\|regexp\)

does match.  Confusing, yes, but useful nevertheless.

Joel
-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109
Public key: http://pgp.mit.edu
http://www.unc.edu/~adamsonj




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-05-22 17:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.12639.1130257485.20277.help-gnu-emacs@gnu.org>
2005-10-25 17:16 ` Trouble with regexp rgb
2005-10-25 17:38   ` exits funnel
2005-10-25 17:54   ` Pascal Bourguignon
2005-10-25 18:40     ` exits funnel
2005-10-25 17:17 ` Chris McMahan
     [not found] <mailman.12018.1211472045.18990.help-gnu-emacs@gnu.org>
2008-05-22 16:31 ` David Kastrup
2008-05-22 16:00 TheLonelyStar
2008-05-22 16:47 ` Alan Mackenzie
2008-05-22 17:27   ` Joel J. Adamson
  -- strict thread matches above, loose matches on Subject: below --
2005-10-25 16:24 exits funnel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).