正则表达式
正则表达式(regular expression)用于指定字符串模式,你可以在任何需要定位匹配某种特定模式的字符串的情况下使用正则表达式。 grep,Perl,Tcl,Python,PHP,and awk都提供了正则表达式的功能特性,但各自语法都不尽相同,java.util.regex和Perl语法最为相似。java.util.regexpackage 主要有三个类组成:Pattern,Matcher,andPatternSyntaxException. ----APatternobject is a compiled representation of a regular expression. ThePatternclass provides no public constructors. To create a pattern,you must first invoke one of itspublic static compilemethods,which will then return aPatternobject. These methods accept a regular expression as the first argument; the first few lessons of this trail will teach you the required syntax. ----AMatcherobject is the engine that interprets the pattern and performs match operations against an input string. Like thePatternclass,Matcherdefines no public constructors. You obtain aMatcherobject by invoking thematchermethod on aPatternobject. ----APatternSyntaxExceptionobject is an unchecked exception that indicates a syntax error in a regular expression pattern.
The metacharacters(通配符) supported by this API are:<([{^-=$!|]})?*+.>
There are two ways to force a metacharacter to be treated as an ordinary character:
When using this technique,the (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |