a sequence of characters that specifies a search pattern
Reference
- Wikipedia EN ( better )
- Wikipedia ZH
- 百度百科
Online tester & debugger: PHP, PCRE, Python, Golang & JavaScript
Since the 1980s, different syntaxes for writing regular expressions exist, one being the POSIX standard and another, widely used, being the Perl syntax.
Usage: todo oneday
Add whitespaces between Chinese & English words ( imperfect )
([^a-zA-Z0-9`'"_\-\s\(\),\.#\[\]=?{}/*@:])([a-zA-Z0-9`'"_\-\(\),\.#\[\]=?{}/*@:]+)([^a-zA-Z0-9`'"_\-\s\(\),\.#\[\]=?{}/*@:])
$1 $2 $3
Add a whitespace after comma ,
,([^ \n]+)
, $1
Date Range
([0-9]{4})\s*?[/\-.年]\s*?([0-9]{1,2})\s*?[/\-.月]\s*?([0-9]{1,2})[日]?
# 2020年01月12日 ~ 2020 年 1 月 13 日
Replace HTML Tag
- Bold
<b[^>]*>([^<]*)</b>
\*\*$1\*\*
- Image
<img[^>]*src="([^"]*)"[^>]*/>
![]($1)
- Link
<a href="([^"]*)"[^>]*>([^<]*)</a>
[$2]($1)
Link Match
\[([^\]]+)\]\(([^\)]+)\)
# Title : $1
# Link : $2
Find function with 7 params
functionName\(([^,^;]*,\s?){6}([^;^,]*?)\)
Replace "" with ''
"([^"]*)"
'$1'
^\[[^\]]*\]
# e.g.
[ERROR]
[WARN]
[INFO]
# original
(?<!^) (?! )
# improve 1
(?<!^)\s{2}(?! )
# improve 2
(?<!^| )\s{2}(?! )
# improve 3
(?<!^|\s)\s{2}(?!\s)
Pattern Match
(pattern)
匹配获取 Capturing Parenthesis(?:pattern)
非匹配获取 Non-Capturing Parenthesis- e.g.
(Windows )(?:\d+)
Windows 98
matchedWindows 2000
matchedWindows XP
not matched
- e.g.
(?=pattern)
正向肯定预查 Lookahead Positive Assertions- e.g.
Windows (?=98)
Windows 98
matchedWindows XP
not matched
- e.g.
(?!pattern)
正向否定预查 Lookahead Negative Assertions- e.g.
Windows (?!98)
Windows XP
matchedWindows 98
not matched
- e.g.
(?<=pattern)
反向肯定预查 Lookbehind Positive Assertions- e.g.
(?<=My) Windows
My Windows
matchedX Windows
not matched
- e.g.
(?<!pattern)
反向否定预查 Lookbehind Negative Assertions- e.g.
(?<!My) Windows
X Windows
matchedMy Windows
not matched
- e.g.