参考 – 这个正则表达式是什么意思?

这是什么?

这是一个常见的Q& A的集合。这也是一个社区Wiki,所以大家被邀请参与维护它。

为什么是这样?

regex是给我我的代码类型的问题和穷人的答案,没有解释。此引用意在提供到质量问答的链接

范围是什么?

此引用适用于以下语言:php,perl,javascript,python,ruby,java,.net

这可能过于宽泛,但这些语言具有相同的语法。对于特定的功能,有它背后的语言的标签,例如:

>什么是正则表达式平衡组? .net

堆栈溢出正则表达式常见问题

量词

>零或更多:*:greedy,[*?:不愿] [需要链接],*+:possessive
>一个或多个:+:greedy,[?:reluctant] [需要链接],++:possessive
> ?:optional (zero-or-one)
>最小/最大范围(全部):{n,m}:between n & m,{n,}:n-or-more,{n}:exactly n
>贪婪,勉强(又名“懒惰”,“不y”)和占有量词的区别:

> Greedy vs. Reluctant vs. Possessive Quantifiers
> In-depth discussion on the differences between greedy versus non-greedy
> What’s the difference between {n} and {n}?
> Can someone explain Possessive Quantifiers to me? phpperljavaruby
> Emulating possessive quantifiers .net
>非stackoverflow参考:从Oracleregular-expressions.info

字符类

> What is the difference between square brackets and parentheses?
> [...]:任何一个字符,[^...]:否定/任何字符
> [^] matches any one character including newlines javascript
> [\w-[\d]] / [a-z-[qz]]:设置减法.netxml-schemaxpath,JGSoft
> [\w&&[^\d]]: set intersection javaruby 1.9
> [[:alpha:]]:POSIX字符类
> Why do [^\\D2],[^[^0-9]2],[^2[^0-9]] get different results in Java? java
>短手:

> Digit:\d:digit\D:non-digit
>字符(字母,数字,下划线):\w:word character\W:non-word character
>空白:\s:whitespace\S:non-whitespace

> Unicode categories (\p{L},\P{L},etc.)

转义序列

>水平空白:\h:space-or-tab\t:tab
>换行:

> \r,\n:carriage return and line feed
> \R:generic newline php

>否定空白序列:\H:Non horizontal whitespace character,\V:Non vertical whitespace character,\N:Non line feed character pcre php5 java-8
>其他:\v:vertical tab\e:the escape character

锚点

> ^:start of line/input\b:word boundary,and \B:non-word boundary$:end of line/input
> \A:start of input,\Z:end of input phpperlpythonruby
> \G:start of match phpperlruby

(另请参见“风味特定信息> Java>在Matcher中的函数”)

> (...):capture group,(?:):non-capture group

> Why is my repeating capturing group only capturing the last match?

> \1:backreference and capture-group reference,$1:capture group reference

> \g<1>123:How to follow a numbered capture group,such as \1,with a number?: python

> What does a subpattern (?i:regex) mean?
> What does the ‘P’ in (?P<group_name>regexp) mean?
> (?>):atomic groupindependent group,(?|):branch reset

> Equivalent of branch reset in .NET/C# .net

>命名捕获组:

> java:(?< groupname> regex):Overviewnaming rules(Non stackoverflow links)
>其他语言:(?P<groupname>regex) python,(?<groupname>regex) .net,(?<groupname>regex) perl,(< group name> regex)和(?< groupname> regex)php

环境

> Lookaheads:(?=...):positive(?!...):negative
> Lookbehinds:(?<=...):positive(?<!...):negative(不受javascript支持)
> Lookbehind限制:

> Lookbehinds need to be constant-length phpperlpythonruby
> Lookarounds of limited length {0,n} java
> Variable length lookbehinds are allowed .net

> Lookbehind替代方案:

> Using \K phpperl(Flavors that support \K)
> Alternative regex module for python python

> The hacky way
> Javascript negative lookbehind equivalents External link

修饰符

>最多风味:g:globali:case-insensitiveu:unicodex:whitespace-extended
> c:current position perl e:expression php perl o:once ruby
> m:multiline php perl python javascript .net javam:(non)multiline ruby
> s:single line(不支持javascriptruby),s workaround javascript
> S:study php r
> How to convert preg_replace e to preg_replace_callback?
> What are inline modifiers?
> What is ‘?-mix’ in a Ruby Regular Expression

其他:

> |:alternation (OR) operator.:any character[.]:literal dot character
> What special characters must be escaped?
>控制动词(phpperl):(*PRUNE),(*SKIP),(*FAIL) and (*F)

> php only:(*BSR_ANYCRLF)

>递归(phpperl):(?R)(?0) and (?1)(?-1)(?&groupname)

常见任务

> Get a string between two curly braces: {...}
> Match (or replace) a pattern except in situations s1,s2,s3…
> How to find all Youtube video ids in a string using a regex?
>验证:

> Internet:email addresses,urls(主机/端口:regexnon-regex替代方案),passwords
> Numeric:a numbermin-max ranges (such as 1-31)phone numbersdate
>使用regex解析HTML:请参见“常规信息>何时不使用Regex”

高级Regex-Fu

>字符串和数字:

> Regular expression to match line that doesn’t contain a word?
> How does this PCRE pattern detect palindromes?
> Match strings whose length is a fourth power
> How does this regex find triangular numbers?
> How to determine if a number is a prime with regex?
> How to match the middle character in a string with regex?

>其他:

> How can we match a^n b^n with Java regex?
>匹配嵌套括号

> Using a recursive pattern phpperl
> Using balancing groups .net

> “Vertical” regex matching in an ASCII “image”
> List of highly up-voted regex questions on Code Golf
> How to make two quantifiers repeat the same number of times?
> An impossible-to-match regular expression: (?!a)a
> Match/delete/replace this except in contexts A,B and C

风味特异性信息

(除了那些用*标记的部分,这部分包含非堆栈溢出链接。)

> Java

>官方文档:Pattern Javadoc,Oracle’s regular expressions tutorial
> java.util.regex.Matcher中的功能间的区别:

> matches()):匹配必须锚定到input-start和-end
> find()):匹配可以在输入字符串(子串)中的任何位置
> lookingAt():匹配必须仅锚定到输入启动
>(对于锚,一般来说,参见“锚点”一节)

>接受正则表达式的唯一的java.lang.String函数matches(s)replaceAll(s,s)replaceFirst(s,s)split(s)split(s,i)
> * An (opinionated and) detailed discussion of the disadvantages of and missing features in java.util.regex

> .NET

> How to read a .NET regex with look-ahead,look-behind,capturing groups and back-references mixed together?

>官方文档:

> Boost regex引擎:General syntax,Perl syntax(由TextPad,Sublime Text,UltraEdit,…使用)
> JavaScript 1.5 general infoRegExp object
> .NET MySQL Oracle Perl5 version 18.2
> PHPpattern syntaxpreg_match
> Python:Regular expression operationssearch vs matchhow-to
> Splunk:regex terminology and syntaxregex command
> Tcl:regex syntax,manpage,regexp command

一般信息

(标有*的链接是非堆栈溢出链接。)

>其他一般文档资源:Learning Regular Expressions,* Regular-expressions.info,* Wikipedia entry,* RexEggOpen-Directory Project
> DFA versus NFA
> Generating Strings matching regex
>图书:Jeffrey Friedl’s * Mastering Regular Expressions
>何时不使用正则表达式:

> * Some people,when confronted with a problem,think “I know,I’ll use regular expressions.” Now they have two problems.(博客Stack Overflow的创始人写)
>不要使用正则表达式来解析HTML:

> Don’t.Please,just don’t
> Well,maybe…if you’re really determined(这个问题的其他答案也不错)

可能导致正则表达式引擎失败的正则表达式示例

> Why does this regular expression kill the Java regex engine?

工具:测试者和解释者

(此部分包含非Stack Overflow链接。)

>在线(*包括更换测试仪,包括分体测试仪):

> Debuggex(还有一个有用的正则表达式库)javascriptpythonpcre
> * Regular Expressions 101 phppcrepythonjavascript
> Regex Pal,* regular-expressions.info javascript
> Rubular ruby RegExr Regex Hero dotnet
> * regexstorm.net .net
> * RegexPlanet:Java java,Go goHaskell haskell,php javascript,.NET dotnet,Perl perl php PCRE php,Python python,Ruby ruby,XRegExp xregexp
> freeformatter.com xregexp
> * regex.larsolavtorvik.com php PCRE和POSIX,javascript
> Refiddle javascript ruby .net

>离线:

> Microsoft Windows:RegexBuddy(分析),RegexMagic(创建),Expresso(分析,创建,免费)

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...