`

java正则表达式

    博客分类:
  • Java
 
阅读更多

 

1

Regular Expression Description
. Matches any character
^regex Finds regex that must match at the beginning of the line.
regex$ Finds regex that must match at the end of the line.
[abc] Set definition, can match the letter a or b or c.
[abc][vz] Set definition, can match a or b or c followed by either v or z.
[^abc] When a caret appears as the first character inside square brackets, it negates the pattern. This can match any character except a or b or c.
[a-d1-7] Ranges: matches a letter between a and d and figures from 1 to 7, but not d1.
X|Z Finds X or Z.
XZ Finds X directly followed by Z.
$ Checks if a line end follows.

2

Regular Expression Description
\d Any digit, short for [0-9]
\D A non-digit, short for [^0-9]
\s A whitespace character, short for [ \t\n\x0b\r\f]
\S A non-whitespace character, short for [^\s]
\w A word character, short for [a-zA-Z_0-9]
\W A non-word character [^\w]
\S+ Several non-whitespace characters
\b Matches a word boundary where a word character is [a-zA-Z0-9_].

3

Regular Expression Description Examples
* Occurs zero or more times, is short for {0,} X* finds no or several letter X,
.* finds any character sequence
+ Occurs one or more times, is short for {1,} X+ - Finds one or several letter X
? Occurs no or one times, ? is short for {0,1}. X? finds no or exactly one letter X
{X} Occurs X number of times, {} describes the order of the preceding liberal \d{3} searches for three digits, .{10} for any character sequence of length 10.
{X,Y} Occurs between X and Y times, \d{1,4} means \d must occur at least once and at a maximum of four.
*? ? after a quantifier makes it a reluctant quantifier. It tries to find the smallest match.  

4

s.matches("regex") Evaluates if "regex" matches s. Returns only true if the WHOLE string can be matched.
s.split("regex") Creates an array with substrings of s divided at occurrence of "regex". "regex" is not included in the result.
s.replace("regex"), "replacement" Replaces "regex" with "replacement

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    java正则表达式.zip

    Java正则表达式是Java编程语言中用于处理字符串的强大工具,它基于模式匹配的概念,能够高效地进行文本搜索、替换和解析。在Java中,正则表达式主要通过`java.util.regex`包来实现,提供了Pattern和Matcher两个核心...

    java正则表达式匹配工具

    Java正则表达式匹配工具是IT领域中一种强大的文本处理工具,它利用正则表达式(Regular Expression)的规则来查找、替换或者提取文本中的特定模式。正则表达式是一种特殊的字符序列,能够帮助程序员或者用户高效地...

    java正则表达式验证IP地址

    Java正则表达式验证IP地址 Java正则表达式验证IP地址是指使用Java语言中的正则表达式来验证IP地址是否符合标准。IP地址是指在网络通信中用来标识设备的地址,它是一种逻辑地址,通过它可以找到网络中的设备。在...

    java 正则表达式应用jar包 regex-smart.jar

    Java正则表达式是编程语言Java中的一个强大工具,它用于模式匹配、数据验证和文本检索替换。在Java中,正则表达式是通过java.util.regex包提供的接口和类来实现的。`regex-smart.jar`这个库显然是为了简化开发者在...

    使用Java正则表达式分析处理日志

    本篇将围绕“使用Java正则表达式分析处理日志”这一主题,探讨如何利用Java的正则表达式功能来提取、过滤和操作日志数据。 首先,我们需要理解正则表达式的基本概念。正则表达式(Regular Expression)是一种模式...

    JAVA正则表达式大全

    以下是对这些文档标题所涉及的Java正则表达式知识点的详细解释: 1. **正则表达式之道** 这个主题可能涵盖了正则表达式的基础概念,包括元字符、字符类、量词和分组。元字符如`.`代表任意字符,`^`表示行首,`$`...

Global site tag (gtag.js) - Google Analytics