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.
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
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 "\|". :(
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