POSIX 字符组

来源:互联网 发布:王者世界韩服数据转移 编辑:程序博客网 时间:2024/06/18 09:27

-- Start

什么是 POSIX 呢? POSIX 是 Portable Operating System Interface (可移植操作系统接口) 的缩写,它是一系列标准,确保操作系统之间的移植性。通常支持正则表达式的工具都支持下列 POSIX 字符组。

元字符(Metacharacter)匹配(Matches)[[:alnum:]]字母和数字[[:alpha:]]字母[[:blank:]]空格和制表符[[:cntrl:]]控制字符[[:digit:]]数字[[:graph:]]非空白字符[[:lower:]]小写字母[[:print:]]类似[[:graph:]],但是包含空白字符[[:punct:]]标点符号[[:space:]]空白字符[[:upper:]]大写字母[[:xdigit:]]十六进制中容许出现的数字(例如 0-9a-fA-f)


下面是一个简单的例子。

#!/usr/bin/perl    my $testText = "I love  regular expressions.";if($testText =~ m/reg[[:alpha:]]lar/) {    print "finds the word.";} else {      print "cannot find the word.";}

public static void main(String[] args) {    String testText = "I love regular expressions.";    String regExp = "reg\\p{Alpha}lar";    Pattern p = Pattern.compile(regExp);    Matcher m = p.matcher(testText);    if (m.find()) {        System.out.println("finds the word.");    } else {        System.out.println("cannot find the word.");    }}

--更多参见:正则表达式精萃
-- 声 明:转载请注明出处
-- Last Updated on 2012-05-10
-- Written by ShangBo on 2012-05-10
-- End


原创粉丝点击