What is this?
This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining it.
Why is this?
regex is suffering from give me ze code type of questions and poor answers with no explanation. This reference is meant to provide links to quality Q&A.
What's the scope?
This reference is meant for the following languages: php, perl, javascript, python, ruby, java, .net.
This might be too broad, but these languages share the same syntax. For specific features there's the tag of the language behind it, example:
- What are regular expression Balancing Groups? .net
Answer
The Regular Expressions FAQ
See also a lot of general hints and useful links at the regex tag details page.
Online tutorials
Quantifiers
- Zero-or-more:
*
:greedy,*?
:reluctant,*+
:possessive - One-or-more:
+
:greedy,+?
:reluctant,++
:possessive ?
:optional (zero-or-one)- Min/max ranges (all inclusive):
{n,m}
:between n & m,{n,}
:n-or-more,{n}
:exactly n - Differences between greedy, reluctant (a.k.a. "lazy", "ungreedy") and possessive quantifier:
Character Classes
Escape Sequences
Anchors
^
:start of line/input,\b
:word boundary, and\B
:non-word boundary,$
:end of line/input\A
:start of input,\Z
:end of input php, perl, ruby\z
:the very end of input (\Z
in Python) .net, php, pcre, java, ruby, icu, swift, objective-c\G
:start of match php, perl, ruby
(Also see "Flavor-Specific Information → Java → The functions in Matcher
")
Groups
Lookarounds
Modifiers
Other:
Common Tasks
Advanced Regex-Fu
- Strings and numbers:
- Other:
Flavor-Specific Information
(Except for those marked with *
, this section contains links.)
- Java
- .NET
- Official documentation:
General information
(Links marked with *
are links.)
Examples of regex that can cause regex engine to fail
Tools: Testers and Explainers
(This section contains links.)
Online (* includes replacement tester, + includes split tester):
- Debuggex (Also has a repository of useful regexes) javascript, python, pcre
- *Regular Expressions 101 php, pcre, python, javascript
- Regex Pal, regular-expressions.info javascript
- Rubular ruby RegExr Regex Hero dotnet
- *+ regexstorm.net .net
- *RegexPlanet: Java java, Go go, Haskell haskell, JavaScript javascript, .NET dotnet, Perl perl php PCRE php, Python python, Ruby ruby, XRegExp xregexp
freeformatter.com
xregexp- *+
regex.larsolavtorvik.com
php PCRE and POSIX, javascript - Refiddle javascript ruby .net
Offline:
No comments:
Post a Comment