24
三
常用正则表达式
前一段时间写了2段EmEditor的宏,用来统计代码行数和简单的规约检查,稍微整理一下,
下面是从EmEditor的Q&A的提取的实例:
双引号包含的字符串
strings surrounded by double-quotation marks
“.*?”[ ]包含的字符串
strings surrounded by [ ]
\[[^\[]*?\]变量名
variable names
[a-zA-Z_][a-zA-Z_0-9]*IP 地址
IP addresses
([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})网页地址
URL
(\S+)://([^:/]+)(:(\d+))?(/[^#\s]*)(#(\S+))?各行Tab以后的文字列
lines followed by a tab
\t.*$平仮名 ひらがな
Hiragana
[\x{3041}-\x{309e}]全角片仮名 全角カタカナ
Full-width Katakana
[\x{309b}-\x{309c}\x{30a1}-\x{30fe}]半角仮名 半角カナ
Half-width Kana
[\x{ff61}-\x{ff9f}]中日韩 汉字
CJK ideographs
[\x{3400}-\x{9fff}\x{f900}-\x{fa2d}]中日韩 汉字符号
CJK ideograph marks
[\x{3000}-\x{3037}]韩国字符
Hangul
[\x{1100}-\x{11f9}\x{3131}-\x{318e}\x{ac00}-\x{d7a3}]行头插入 //
Insert // at start of lines
Find: ^
Replace with: //删除行头 //
Remove // at end of lines
Find: ^//
Replace:删除行后的空白文字(包含空格和制表位 Space+Tab)
Remove trailing whitespaces
Find: \s+?$
Replace with:将(abc)替换为[abc]
Replace (abc) with [abc]
Find: \((.*?)\)
Replace: \[\1\]将<H3 …>替换为<H4 …>
Replace <H3 …> with <H4 …>
Find: <H3(.*?)>
Replace: <H4\1>将9/13/2003替换为2003年9月13日
Replace 9/13/2003 with 2003.9.13
Find: ([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})
Replace: \3年\1月\2日将字母a-z替换为大写字母
Uppercase characters from a to z
Find: [a-z]
Replace: \U\0首字母大写
Capitalize all words
Find: ([a-zA-Z])([a-zA-Z]*)
Replace: \U\1\L\2
中文关键字:regular expression 正则表达式 emeditor 宏 符号 正则 表达式 常用 replace 全角 find 汉字 半角 with 行头
相关日志 :
Tags: Regular Expression, 正则表达式
This entry was posted
on 星期一, 三月 24th, 2008 at 6:13 下午 and is filed under 软件开发.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
One comment
Leave a reply