didn't know the regexp org-ts-regexp-*. Thanks!

On Thu, May 29, 2014 at 10:59 AM, Bastien <b...@gnu.org> wrote:

> Hi,
>
> zhenjiang zech xu <zhenjiang...@gmail.com> writes:
>
> > For a simple example, assuming current entry is:
> >
> > * [2014-05-06 Thu] this is the heading
> >    blahblah...
> >
> > I'd like to get the time string and the title "this is the heading"
> > separately. Is there a canonical way to do that with org-mode APIs?
>
> This function returns a CONS with the timestamp and the rest of the
> heading:
>
> (defun get-timestamp-and-heading ()
>   (interactive)
>   (save-excursion
>     (org-back-to-heading t)
>     (let* ((h (org-element-property :raw-value (org-element-at-point)))
>            (h-no-ts (replace-regexp-in-string org-ts-regexp-both "" h))
>            (ts (and (string-match org-ts-regexp-both h)
>                     (match-string 0 h))))
>       (cons (org-trim h-no-ts) ts))))
>
> HTH,
>
> --
>  Bastien
>

Reply via email to