unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help with emacs regexp
@ 2007-08-22 18:32 DaLoverhino
  2007-08-22 18:41 ` DaLoverhino
  0 siblings, 1 reply; 3+ messages in thread
From: DaLoverhino @ 2007-08-22 18:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hello.  I'm trying to get a little fancier with regexp, but I there's
always this big gulf to the next plain which I can't seem to jump.  :)

I've been trying to write a regexp where all lines that begin with a
white space or opening and closing braces are removed.


I have a C-module with function definitions, and I want to strip out
everything in
the file, but leave the function signature and return type.

So the file looks like this:


static returnType
function1(blah, blah)
{
  if( blah)
  {
    blah;
  }
  blah;
}



returnType
function2(blah, blah)
{
  blah;
  blah;
}

I want it to look like the following after replace-regexp:

static returnType
function1(blah, blah)
returnType
function2(blah, blah)


Here's what I have, it only works partly:

"^\s-+.*
" replace with <nothing>

The above strips everything but the braces, but also removes return
type of all functions but the first.


"^\(\s-\|{\}\)+.*" replace with <nothing>

The above strips everything but the function signature, but it removes
the return type, and leaves a bunch of blank lines.

This doesn't work either:

"^[^a-zA-Z0-9]+?.*\n" replace with <nothing>



Ofcourse, the easiest method would be to:

shell-command-on-region
egrep '^\w'


Can anyone help me out?  Thanks.

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

* Re: Help with emacs regexp
  2007-08-22 18:32 Help with emacs regexp DaLoverhino
@ 2007-08-22 18:41 ` DaLoverhino
  2007-08-23  1:26   ` Joe Fineman
  0 siblings, 1 reply; 3+ messages in thread
From: DaLoverhino @ 2007-08-22 18:41 UTC (permalink / raw)
  To: help-gnu-emacs

On Aug 22, 2:32 pm, DaLoverhino <DaLoveRh...@hotmail.com> wrote:
> Hello.  I'm trying to get a little fancier with regexp, but I there's
> always this big gulf to the next plain which I can't seem to jump.  :)
>
> I've been trying to write a regexp where all lines that begin with a
> white space or opening and closing braces are removed.
>
> I have a C-module with function definitions, and I want to strip out
> everything in
> the file, but leave the function signature and return type.
>
> So the file looks like this:
>
> static returnType
> function1(blah, blah)
> {
>   if( blah)
>   {
>     blah;
>   }
>   blah;
>
> }
>
> returnType
> function2(blah, blah)
> {
>   blah;
>   blah;
>
> }
>
> I want it to look like the following after replace-regexp:
>
> static returnType
> function1(blah, blah)
> returnType
> function2(blah, blah)
>
> Here's what I have, it only works partly:
>
> "^\s-+.*
> " replace with <nothing>
>
> The above strips everything but the braces, but also removes return
> type of all functions but the first.
>
> "^\(\s-\|{\}\)+.*" replace with <nothing>
>
> The above strips everything but the function signature, but it removes
> the return type, and leaves a bunch of blank lines.
>
> This doesn't work either:
>
> "^[^a-zA-Z0-9]+?.*\n" replace with <nothing>
>
> Ofcourse, the easiest method would be to:
>
> shell-command-on-region
> egrep '^\w'
>
> Can anyone help me out?  Thanks.

Dang it!! I just figured it out:

"^\Sw+?.*
" replace with <nothing>

Anyways, I have to use C-q C-j.  Using \n for the new line just does
not seem to work.  How come?

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

* Re: Help with emacs regexp
  2007-08-22 18:41 ` DaLoverhino
@ 2007-08-23  1:26   ` Joe Fineman
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Fineman @ 2007-08-23  1:26 UTC (permalink / raw)
  To: help-gnu-emacs

DaLoverhino <DaLoveRhino@hotmail.com> writes:

> Anyways, I have to use C-q C-j.  Using \n for the new line just does
> not seem to work.  How come?

That syntax works only in Elisp code, not in interactive replacement.
Likewise, you have to use C-q TAB, not \t.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  There are no violet stars.  :||

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

end of thread, other threads:[~2007-08-23  1:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-22 18:32 Help with emacs regexp DaLoverhino
2007-08-22 18:41 ` DaLoverhino
2007-08-23  1:26   ` Joe Fineman

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).