正则表达式
来源:互联网 发布:南风知我意 书包网 编辑:程序博客网 时间:2024/06/08 05:50
BasicPatterns
The power ofregular expressions is that they can specify patterns, not justfixed characters. Here are the most basic patterns which matchsingle chars:
a, X, 9, < -- ordinary characters just matchthemselves exactly. The meta-characters which do not matchthemselves because they have special meanings are: . ^ $ * + ? { [] \ | ( ) (details below)
. (a period) -- matches any single character except newline'\n'
\w -- (lowercase w) matches a "word" character: a letter ordigit or underbar [a-zA-Z0-9_]. Note that although "word" is themnemonic for this, it only matches a single word char, not a wholeword. \W (upper case W) matches any non-word character.
\b -- boundary between word and non-word
\s -- (lowercase s) matches a single whitespace character --space, newline, return, tab, form [ \n\r\t\f]. \S (upper case S)matches any non-whitespace character.
\t, \n, \r -- tab, newline, return
\d -- decimal digit [0-9] (some older regex utilities do notsupport but \d, but they all support \w and \s)
^ = start, $ = end -- match the start or end of the string
\ -- inhibit the "specialness" of a character. So, for example,use \. to match a period or \\ to match a slash. If you are unsureif a character has special meaning, such as '@', you can put aslash in front of it, \@, to make sure it is treated just as acharacter.
Repetition
Things get moreinteresting when you use + and * to specify repetition in thepattern
- + -- 1or more occurrences of the pattern to its left, e.g. 'i+' = one ormore i's
- * -- 0or more occurrences of the pattern to its left
- ? --match 0 or 1 occurrences of the pattern to its left
- 【正则表达式】正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- Fedora 设置第三方软件原
- linux mongodb driver&n…
- python中调用dos命令
- Linux 下好用的QQ
- 简单卷、跨区卷、带区卷、镜像卷和…
- 正则表达式
- RSS技巧
- keytool 不是内部或外部命令
- Python shutil.copy 函数
- 素数
- Ubuntu sun jdk
- Leetcode Binary Tree&n…
- LeetCode:Compare Version Numbers
- Windows Atom 使用