Friday, August 3, 2007

Regular expression compare 各工具正则表达式比较

这篇实在是太好,我不得不抄。。

在各种常用的工具中,
正则表达式如此的相似却又不同。
下表列出了一些常用的正则表达式,以及其不同之处。
项目众多,遗漏必有不少,请各位看官不吝指出。
以perl的正则为基准,不同的用法以粉红色标出。
(xhchen8018 at yahoo.com.cn)这个应该是原作者的mail地址。

我抄袭的原文地址:
http://blog.chinaunix.net/u/634/showart_2466.html


grep 2.5.1egrep 2.5.1sed 3.02


sed 4.07
awk 3.1.1perl 5.8.0vim 6.1JavaScript ??
转义\\\\\\\
行头^^^^^^^
行尾$$$$$$$
n个\
\或\ 仅定义 --posix 或 --re-interval有效(要表达}和 没有定义--posix或--re-interval时,不能用的语法, \}\{同义
\

****或\*, (要表达*,得用\\*)***

\++\++或\+, (要表达+, 得用\\+)+\++

\??\??或\?, (要表达?, 得用\\?)?\??
任意字符.... 含\n.. /s修饰后则含\n. 除\n. 除\n
(pat) 匹配并获结果\(pat\)(pat)\(pat\)(pat)或\(pat\) (要表达括号,用\\( \\) )(pat)\(pat\)(pat)
(?:pat) 匹配但不获结果不支持不支持不支持不支持(?:pat)不支持(?:pat)
(?=pat) 等于预查不支持不支持不支持不支持(?=pat)不支持(?=pat)
(?!pat) 不等预查不支持不支持不支持不支持(?!pat)不支持(?!pat)
| 或\||\||或\| (要表达|,得用\\|)|\||
其中任意字符[xyz][xyz][xyz][xyz][xyz][xyz][xyz]
[.ch.] [=ch=]不支持不支持[.ch.]不支持不支持不支持不支持
单词边界 \b\b\b\b不支持\b不支持\b
非单词边界 \B\B\B\B不支持\B不支持\B
单词左右边界 <>\< \>\< \>\< \>不支持 (><和\>\<和\\>\\<同义不支持(><和\>\<同义\< \>不支持(><和\>\<同义
控制字符 /cx不支持不支持\cx不支持\cx不支持\cx
数字\d不支持不支持不支持不支持\d\d\d
非数字\D不支持不支持不支持不支持\D\D\D
换页 \f不支持不支持高版本支持\f\f另义 \f表示文件名字符\f
换行 \n不支持不支持不支持\n\n\n\n
回车 \r不支持不支持\r\r\r\r\r
空白 \s不支持不支持不支持不支持\s\s\s
非空白 \S不支持不支持不支持不支持\S\S\S
制表符 \t不支持不支持高版本支持\t\t\t\t
垂直制表符 \v不支持不支持高版本支持\v\v另义 \v表示very magic\v
单词字符 \w [A-Za-z0-9_]\w\w\w不支持\w\w\w
非单词字符 \W [^A-Za-z0-9]\W\W\W不支持\W\W\W
\xn 16进制不支持不支持高版本支持\xn\xn另义 \x表示[0-9A-Za-z]\xn
\n 八进制不支持不支持不支持\n\n不支持\n
\n 后向引用\n\n\n\n 仅取结果可用\n\n 仅取结果可用\n
[:alnum:] 字母和数字[:alnum:][:alnum:][:alnum:][:alnum:][:alnum:][:alnum:]不支持
[:alpha:] 字母[:alpha:][:alpha:][:alpha:][:alpha:][:alpha:][:alpha:]不支持
[:cntrl:] 控制字符[:cntrl:][:cntrl:][:cntrl:][:cntrl:][:cntrl:][:cntrl:]不支持
[:digit:] 数字[:digit:][:digit:][:digit:][:digit:][:digit:][:digit:]不支持
[:graph:] 可打印字符(不含空格)[:graph:][:graph:][:graph:][:graph:][:graph:][:graph:]不支持
[:lower:] 小写[:lower:][:lower:][:lower:][:lower:][:lower:][:lower:]不支持
[:print:] 可打印字符(含空格)[:print:][:print:][:print:][:print:][:print:][:print:]不支持
[:punct:] 标点[:punct:][:punct:][:punct:][:punct:][:punct:][:punct:]不支持
[:space:] 空格[:space:][:space:][:space:][:space:][:space:][:space:]不支持
[:upper:] 大写字母[:upper:][:upper:][:upper:][:upper:][:upper:][:upper:]不支持
[:xdigit:] 16进制数字[:xdigit:][:xdigit:][:xdigit:][:xdigit:][:xdigit:][:xdigit:]不支持
[:return:] <CR>不支持不支持不支持不支持不支持[:return:]不支持
[:tab:] <TAB>不支持不支持不支持不支持不支持[:tab:]不支持
[:escape:] <ESC>不支持不支持不支持不支持不支持[:escape:]不支持
[:backspace:] <BS>不支持不支持不支持不支持不支持[:backspace:]不支持

Saturday, July 21, 2007

用Visual Studio 2005 集成环境开发QT程序(Opensource版)qt4.3.2

#define 我也是个新手……

我建立的是一个Windows环境。
使用VC2005编译源代码完成。
首先,下载QT-win-opensource版本。我下载的是4.3.2版本。此版本原生支持用VC,VC.net,VC2005编译。
然后,把它解压缩到一个你需要的地方。
我是放在了c:\qt\4.3.2-vc2005\
然后,新建一个系统变量QMAKESPEC
值为win32-msvc2005

c:\qt\4.3.0-vc2005\bin; 添加到系统path变量里去。另外,记得,每个路径都要用英文分号;来分割。

然后运行
VC2005命令行
VC2005命令行(如上图)
打开后,cd 进入上面的c:\qt\4.3.2-vc2005\
时,输入
configure
然后得到一堆输出

You are now ready to build Qt (msvc2005)If you specified -static, type 'nmake sub-src'
otherwise, type 'nmake'

To start over, type 'nmake distclean'
and then re-run configure.exe

然后,输入nmake回车,就开始漫长的编译过程。(如果你很在意编译时间,可以先输入nmake sub-src只编译库,这样,也会少占用很多硬盘空间)

再然后,就可以编辑一个Qt测试程序测试是否安装成功了。
建立一个文件
main.cpp
输入以下内容

#include <QApplication>

#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QPushButton hello("Hello world!");

hello.resize(100, 30);

hello.show();

return app.exec();
}

保存后,开启刚才的VC命令行,一定要是VC命令行,然后,cd到源文件保存的目录,按顺序输入

qmake -project
qmake
nmake
没有输入错误的话,就会发现,已经自动生成了debug目录,并且,生成了debug版本的程序。
运行一下,就可以看到结果了。
nmake release
就可以生成release版本的程序。

Saturday, July 14, 2007

让编译好的程序在别人电脑运行

写好的程序,编译,链接,运行正常后,copy到别人电脑硬是没法运行……
这里有个解决的办法。

MSVC2005有个自带的不错的工具depends。它可以检测出一个程序运行时,需要调用哪些dll库文件。

通过这个程序,找到自己的程序所需要的dll,最简单的办法是把它们都copy到程序所在目录,然后一起发给客户。

这个工具一般存在于
Microsoft Visual Studio 8\Common7\Tools\Bin\

名字为depends.exe

Friday, June 29, 2007

C++的开始

c++取得命令行参数


/*
* c++取得命令行参数
*/
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main (int argc, char *argv[])
{
char * p;
for(int i=0;i<argc;i++){
p=argv[i];
while(*p!='\0'){
cout<<(char)*p;
p++;
}
cout<<endl;
}
cout << "Press ENTER to continue..." << endl;
cin.get();
return 0;
}