all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Regex Problem
@ 2008-07-19 17:50 travis jeffery
  0 siblings, 0 replies; 10+ messages in thread
From: travis jeffery @ 2008-07-19 17:50 UTC (permalink / raw
  To: Help-gnu-emacs


I'm trying to write and extension for using tumbr. In tumblr there are two
requirements for a post; title and body. 

So I set up a tumblr post document as:
title:
body:

So get the title I use (string-match "\\title: \(.*\)\$"), which is fine
because it's on a single line. But with I'm having trouble getting the body
because it's multiple lines. So is there someway I can get any text
following the body:_space_? I was thinking also of saving the entire buffer
and then subtracting the title: TITLE and body:_space_ but I still don't
know about that. 

Thanks for your help.
-- 
View this message in context: http://www.nabble.com/Regex-Problem-tp18547090p18547090.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





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

* Re: Regex Problem
       [not found] <mailman.15059.1216536041.18990.help-gnu-emacs@gnu.org>
@ 2008-07-20  7:48 ` Xah
  2008-07-21 16:23   ` John Paul Wallington
  2008-07-21 21:47 ` Thr4wn
  1 sibling, 1 reply; 10+ messages in thread
From: Xah @ 2008-07-20  7:48 UTC (permalink / raw
  To: help-gnu-emacs

On Jul 19, 10:50 am, travis jeffery <eatsleepg...@gmail.com> wrote:
> I'm trying to write and extension for using tumbr. In tumblr there are two
> requirements for a post; title and body.
>
> So I set up a tumblr post document as:
> title:
> body:
>
> So get the title I use (string-match "\\title: \(.*\)\$"), which is fine
> because it's on a single line. But with I'm having trouble getting the body
> because it's multiple lines. So is there someway I can get any text
> following the body:_space_? I was thinking also of saving the entire buffer
> and then subtracting the title: TITLE and body:_space_ but I still don't
> know about that.
>
> Thanks for your help.

to get text out of the “body:”, you can do something like this:

(goto-char 1)
(search-forward "body:")
(setq mytext (buffer-substring-no-properties (point) (1+ (buffer-
size))))

for some basic elisp functions, see
 http://xahlee.org/emacs/elisp_common_functions.html

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Regex Problem
  2008-07-20  7:48 ` Regex Problem Xah
@ 2008-07-21 16:23   ` John Paul Wallington
  0 siblings, 0 replies; 10+ messages in thread
From: John Paul Wallington @ 2008-07-21 16:23 UTC (permalink / raw
  To: help-gnu-emacs

Xah <xahlee@gmail.com> writes:

> (setq mytext (buffer-substring-no-properties (point) (1+ (buffer-
> size))))

Just a nitpick: in general you want to use `point-max' rather than
(1+ (buffer-size)) to take into account any narrowing.


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

* Re: Regex Problem
       [not found] <mailman.15059.1216536041.18990.help-gnu-emacs@gnu.org>
  2008-07-20  7:48 ` Regex Problem Xah
@ 2008-07-21 21:47 ` Thr4wn
  2008-07-22 12:29   ` Nikolaj Schumacher
       [not found]   ` <mailman.15163.1216729783.18990.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 10+ messages in thread
From: Thr4wn @ 2008-07-21 21:47 UTC (permalink / raw
  To: help-gnu-emacs

On Jul 19, 1:50 pm, travis jeffery <eatsleepg...@gmail.com> wrote:
> I'm trying to write and extension for using tumbr. In tumblr there are two
> requirements for a post; title and body.
>
> So I set up a tumblr post document as:
> title:
> body:
>
> So get the title I use (string-match "\\title: \(.*\)\$"), which is fine
> because it's on a single line. But with I'm having trouble getting the body
> because it's multiple lines. So is there someway I can get any text
> following the body:_space_? I was thinking also of saving the entire buffer
> and then subtracting the title: TITLE and body:_space_ but I still don't
> know about that.
>
> Thanks for your help.
> --
> View this message in context:http://www.nabble.com/Regex-Problem-tp18547090p18547090.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.

In an emacs regexp, you can directly enter a newline character as a
possible match by hitting C-j (will appear as ^J in the regexp) and/or
C-q C-m (honestly, I'm not exactly sure what the difference between ^J
and ^M is. I think one is \n while the other is \r. Since Windows
requires all lines to end with \r\n, I would allow for either ^J or ^M
in the search).

Also, \' means "end of buffer/string", so using both that knowledge, I
think the following will work...

"^body: ?\(\(.\|^J\|^M\)*\)\'"      (there is a \' at the end of that
string)

Also, I am not certain if I understand why your regexp for title had \
\ at the beginning? wouldn't that match a literal backslash when you
really want just the beginning of the line (^)?

let me know if something I said didn't make sense.

-Thr4wn


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

* Re: Regex Problem
  2008-07-21 21:47 ` Thr4wn
@ 2008-07-22 12:29   ` Nikolaj Schumacher
       [not found]   ` <mailman.15163.1216729783.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Nikolaj Schumacher @ 2008-07-22 12:29 UTC (permalink / raw
  To: Thr4wn; +Cc: help-gnu-emacs

Thr4wn <Seth.A.Bird@gmail.com> wrote:

> In an emacs regexp, you can directly enter a newline character as a
> possible match by hitting C-j (will appear as ^J in the regexp) and/or
> C-q C-m

You can, but you should most definitely not.  It just makes the text
hard to read or edit in anything other than Emacs.  Just use \n.

> Since Windows requires all lines to end with \r\n, I would allow for
> either ^J or ^M in the search).

I believe Emacs buffers will only contain \n even for Windows files.

> On Jul 19, 1:50 pm, travis jeffery <eatsleepg...@gmail.com> wrote:
>> So I set up a tumblr post document as:
>> title:
>> body:
>>
>> So get the title I use (string-match "\\title: \(.*\)\$"), which is fine

What do you mean by document?  A file or a buffer?  If so, why do you
use string-match?  You can just search around in the buffer, which
should be more efficient.

regards,
Nikolaj Schumacher




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

* Re: Regex Problem
       [not found]   ` <mailman.15163.1216729783.18990.help-gnu-emacs@gnu.org>
@ 2008-07-23 19:30     ` Thr4wn
  2008-07-23 19:57       ` Drew Adams
  2008-07-24 11:18       ` Nikolaj Schumacher
  0 siblings, 2 replies; 10+ messages in thread
From: Thr4wn @ 2008-07-23 19:30 UTC (permalink / raw
  To: help-gnu-emacs

On Jul 22, 8:29 am, Nikolaj Schumacher <n_schumac...@web.de> wrote:
> You can, but you should most definitely not.  It just makes the text
> hard to read or edit in anything other than Emacs.  Just use \n.

That's a good point, I didn't think about that.

However, whenever I try to use \n in my regex searches, emacs does not
seem to recognize that as a newline. the regexp syntax documentation
also does not seem to mention any way to refer to a newline.
Am I just missing something?

-Thr4wn


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

* RE: Regex Problem
  2008-07-23 19:30     ` Thr4wn
@ 2008-07-23 19:57       ` Drew Adams
  2008-07-23 22:36         ` Bernardo Bacic
  2008-07-24 11:18       ` Nikolaj Schumacher
  1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2008-07-23 19:57 UTC (permalink / raw
  To: 'Thr4wn', help-gnu-emacs

> > You can, but you should most definitely not.  It just makes the text
> > hard to read or edit in anything other than Emacs.  Just use \n.
> 
> That's a good point, I didn't think about that.
> 
> However, whenever I try to use \n in my regex searches, emacs does not
> seem to recognize that as a newline. the regexp syntax documentation
> also does not seem to mention any way to refer to a newline.
> Am I just missing something?

Interactively (e.g. C-M-s), you must use an actual newline character (via C-q
j), not \n.





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

* Re: Regex Problem
  2008-07-23 19:57       ` Drew Adams
@ 2008-07-23 22:36         ` Bernardo Bacic
  2008-07-23 22:43           ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Bernardo Bacic @ 2008-07-23 22:36 UTC (permalink / raw
  To: help-gnu-emacs

it was a dark and stormy night when Drew Adams said,

> Interactively (e.g. C-M-s), you must use an actual newline character (via C-q
> j), not \n.

C-q C-j




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

* RE: Regex Problem
  2008-07-23 22:36         ` Bernardo Bacic
@ 2008-07-23 22:43           ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2008-07-23 22:43 UTC (permalink / raw
  To: bernardo.bacic, help-gnu-emacs

> > Interactively (e.g. C-M-s), you must use an actual newline 
> > character (via C-q j), not \n.
> 
> C-q C-j

Oops, thanks; that's what I meant.





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

* Re: Regex Problem
  2008-07-23 19:30     ` Thr4wn
  2008-07-23 19:57       ` Drew Adams
@ 2008-07-24 11:18       ` Nikolaj Schumacher
  1 sibling, 0 replies; 10+ messages in thread
From: Nikolaj Schumacher @ 2008-07-24 11:18 UTC (permalink / raw
  To: Thr4wn; +Cc: help-gnu-emacs

Thr4wn <Seth.A.Bird@gmail.com> wrote:

> However, whenever I try to use \n in my regex searches, emacs does not
> seem to recognize that as a newline. the regexp syntax documentation
> also does not seem to mention any way to refer to a newline.
> Am I just missing something?

You're not.  \n is in fact not part of the regexp syntax.  It's part
of the lisp string syntax.  It's the same reason you need to use only
one \ interactively, but two in lisp.

By the way, if you are designing regular expressions, it's usually
easier to use `re-builder' than interactive search.


regards,
Nikolaj Schumacher




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

end of thread, other threads:[~2008-07-24 11:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.15059.1216536041.18990.help-gnu-emacs@gnu.org>
2008-07-20  7:48 ` Regex Problem Xah
2008-07-21 16:23   ` John Paul Wallington
2008-07-21 21:47 ` Thr4wn
2008-07-22 12:29   ` Nikolaj Schumacher
     [not found]   ` <mailman.15163.1216729783.18990.help-gnu-emacs@gnu.org>
2008-07-23 19:30     ` Thr4wn
2008-07-23 19:57       ` Drew Adams
2008-07-23 22:36         ` Bernardo Bacic
2008-07-23 22:43           ` Drew Adams
2008-07-24 11:18       ` Nikolaj Schumacher
2008-07-19 17:50 travis jeffery

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.