Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/niklongstone/regular-expression-cheat-sheet

Regular Expression Cheat Sheet - PCRE
https://github.com/niklongstone/regular-expression-cheat-sheet

Last synced: about 2 months ago
JSON representation

Regular Expression Cheat Sheet - PCRE

Awesome Lists containing this project

README

        

# Regular Expression Cheat Sheet - PCRE

|Anchor|Description|Example|Valid match|Invalid|
:---|:---|:---|:---|---
^|start of string or line|^foam|foam|bath foam|
\A|start of string in any match mode|\Afoam|foam|bath foam|
$|end of string or line|finish$|finish|finnish|
\Z|end of string, or char before last new line in any match mode|finish\Z|finish|finnish|
\z|end of string, in any match mode.|
\G|end of the previous match or the start of the string for the first match|\^(get\|set)\|\G\w+$|setValue|seValue
\b|word boundary; position between a word character (\w), and a nonword character (\W)|\bis\b|This island is beautiful|This island isn't beautiful
\B|not-word-boundary.|\Bland|island|peninsula

|Assertion|Description|Example|Valid match|Invalid|
:---|:---|:---|:---|---
(?=...)|positive lookahead|question(?=s)|questions|question
(?!...)|negative lookahead|answer(?!s)|answer| answers
(?<=...)|positive look-behind|(?<=appl)e|apple|application
(?...)|subpattern, and capture submatch into *name*|`(?Phello)`|hello|hallo
(?:...)|subpattern, but does not capture submatch|(?:hello)|hello|hallo
+| one or more quantifier|ye+ah|yeah, yeeeah|yah
*| zero or more quantifier|ye*ah|yeeah, yeeeah, yah|yeh
?| zero or one quantifier|yes?|yes, ye|yess
??| zero or one, as few times as possible (lazy)|yea??h|yeah|yeaah|
+?| one or more lazy |`/<.+?>/g`|`

foo

` matches only `

` and `

`|
*?| zero or more, lazy|`/<.*?>/g`|``|
{n}|n times exactly|fo{2}|foo|fooo
{n,m}|from n to m times|go{2,3}d|good,goood|gooood
{n,}|at least n times|go{2,}|goo, gooo|go
(?(condition)...)|if-then pattern|`(<)?[p](?(1)>)`|`

`, p|