Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regexp problem

4 views
Skip to first unread message

jarzabek

unread,
Jul 4, 2011, 4:34:11 AM7/4/11
to
Hello,

I want to extract middle column using query-replace-regexp from the
following data structure:

0,11 .......... 26661 ........... 08:01:30
2,84 .......... 450 .......... 09:35:30
2,87 .......... 2000 ......... 13:03:44
etc.

To remove first column (and dots) the following expression works:
^.*? .*?
(notice space at the end of the line)

To remove the last column:
\.+ [^ ]+?$
(notice space at the beginning)

Above works well, but the problem is that when I combine these two
expressions with '\|' only first column is removed. I've tried similar
with emacs and it is fine there, so something weird is going on.

Here is the full macro code:
(defalias 'jj
(read-kbd-macro
"M-# ^ .*? SPC .*? SPC \\| SPC \\.+ SPC [^ SPC ]+?$ 2*RET y C-a"))

Any help is appreciated.

nos...@nospam.net

unread,
Jul 6, 2011, 8:40:56 AM7/6/11
to

jarzabek writes:

My solution

(query-replace-regexp "^.* \\([0-9]+\\) .*$" "\\1" nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))

By the way: Do you know

"re-builder.el --- building Regexps with visual feedback"

(part of GNU-Emacs) ?

Martin
--
parozusa at web dot de

jarzabek

unread,
Jul 8, 2011, 2:26:02 AM7/8/11
to

I don't know what transient-mark-mode is and cannot find it in my
xemacs build (isn't it only for gnu emacs?).
Anyway, I ended with the following:

(defun middle-column ()
"Return middle column"
(interactive)
(save-excursion
(while (re-search-backward "^[0-9]+,[0-9]+ \\.+ " (mark) t)
(replace-match "" nil nil))
)
; (save-excursion
(while (re-search-backward " .+" (mark) t)
(replace-match "" nil nil))
; )
)

> By the way: Do you know
>
>   "re-builder.el --- building Regexps with visual feedback"
>
> (part of GNU-Emacs) ?

Wow! That's cool! It is also part of xemacs - at least my 21.5.31 beta
version.
After long years of using this editor I've learned something really
new - thanks!
But... the one thing that I've already realized is that re-builder
doesn't recognize alternative "\|". :(

nos...@nospam.net

unread,
Jul 11, 2011, 4:18:46 AM7/11/11
to

Hi,

jarzabek writes:

> On Jul 6, 2:40 pm, Martin wrote:
...


>> My solution
>>
>> (query-replace-regexp "^.* \\([0-9]+\\) .*$" "\\1" nil (if (and
>> transient-mark-mode mark-active) (region-beginning)) (if (and
>> transient-mark-mode mark-active) (region-end)))
>
> I don't know what transient-mark-mode is and cannot find it in my

What I mean is:

M-x query-replace-regexp RET ^.* \([0-9]+\) .*$ RET \1 RET

"^.* \([0-9]+\) .*$" matches the lines containing a sequence of numeric
characters limited by blanks. "\1" as replacement string refers to the
sequence of numeric characters.


>>   "re-builder.el --- building Regexps with visual feedback"

...


> But... the one thing that I've already realized is that re-builder
> doesn't recognize alternative "\|". :(

Use "\\|".

Cheers

0 new messages