Friday, September 29, 2006

Trick in query-replace-regexp

使用 query-replace-regexp 的小技巧

query-replace-regexp C-M-%

eg. a). delete a blank line

C-M-% ^\s-* C-q C-j [RET][RET]

^ means beginning of a line.
\s- means any white space.
C-q C-j is to insert a new line in the minibuffer. Likely wise, you can use C-q C-i to insert a TAB, etc.
Note, there should be no space between "^\s-*" and "C-q C-j" in the this example!

eg. b). Insert a series of continued number in the beginning of each line.

C-M-% ^ [RET] \# [RET]

\# means the number of replacements, starting with zero.

eg. a). change (2) (3) (4) (5) ... into (4) (5) (6) (7) ...

C-M-% (\([0-9]+\)) [RET] (\,(+ \#1 2)) [RET]

\#1 means convert the match \1 into number. The match \1 is string by default.
\, followed by a lisp expression. So from here you can do almost whatever you want. Yeah!
del.icio.us Tags:

Monday, September 25, 2006

Have to abandon MSVDM for the second time

I love the virtual work space under linux X. I hoped the MSVDM (Microsoft virtual desktop manager) could do the same job as well. However, it let me down again.
The first time it is because it didn't work quite well with ATnote. This time I found it might have bugs in switching work spaces when using different wallpapers for different work spaces. Sometimes the wallpapers were gone. Plus, there are also bugs even in cooperating with Excel. The menu in excel is disappeared when switching to another desktop.
I hate this poor M$ tool.

Saturday, September 09, 2006

Wildcards in Microsoft Word compared with Regular Expressions

在Word里使用部分正则表达式

作为一套昂贵的字处理软件,Word里竟然不可用正则表达式,实在令人发指。不过他的查找替换里可以使用通配符(Wildcards),可以实现一部分的正则表达式功能。

例如:把所有email地址改写 mailto:xxx@gmail.com 的形式,可以用以下操作:
Ctrl-H
more
Use wildcards
Find what: ([a-zA-Z0-9.+_-]@\@[a-zA-Z0-9]@.[a-z]@)
Replace with: mailto:\1
然后替换就可以了。

一些常用的正则表达式(已含所有的 MS Word 可用的通配符)

含义 GNU grep GNU Emacs Perl MS Word
任何单个字符 . . . ?
符合其中的任一字符 [...] [...] [...] [...]
符合除此之外的任一字符 [^...] [^...] [^...] [!...]
子表达式 \(re\) \(re\) ( re) (re)
表达式重复多次 re\{...\} re\{...\} re{...} re{...}
表达式出现0或1次 re\? re? re?
表达式出现0或多次 re* re* re*
表达式出现1或多次 re\+ re + re+ re@
表达式出现0或1次(lazy mode) re?? re??
表达式出现0或多次(lazy mode) re*? re*?
表达式出现1或多次(lazy mode) re +? re+?
单词起始 \ < \< <
单词结尾< /td> \> \> >
单词边界(起始或结尾) \b \b \b
非单词边界 \B \B \B
任意字符串 .* .* .* *
行首 ^ ^ ^
行末 $ $ $
换行符 \n C-q C-j \n ^13
”或“ re\|re re\ |re re|re
引用上次找到的内容 不知道 \& 不知道 ^&
引用被括号捕获的内容 \digit \digit \digit \digit

** 注:re 代表一个正则表达式 (RegExp)
*** MS Word里多次匹配,最少是一次,没有0次。
*** \digit 指 \后面加数字 如 \1 \2
*** 正则表达式里括号子表达式可以嵌套使用,Word里好像不行


del.icio.us Tags: