加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式

发布时间:2020-12-13 21:55:18 所属栏目:百科 来源:网络整理
导读:正则表达式(regular expression)用于指定字符串模式,你可以在任何需要定位匹配某种特定模式的字符串的情况下使用正则表达式。 grep,Perl,Tcl,Python,PHP,and awk都提供了正则表达式的功能特性,但各自语法都不尽相同,java.util.regex和Perl语法最为相似

正则表达式(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:

  • precede the metacharacter with a backslash,or
  • enclose it withinQ(which starts the quote) andE(which ends it).

When using this technique,theQandEcan be placed at any location within the expression,provided that theQcomes first.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读