regex cheat sheet
2024-10-21 09:41:34
regex pattern visualizer : regex101: build, test, and debug regex https://regex101.com/
regex
regex character
character | meaning |
---|---|
\d | digital characters |
\D | not digital characters |
\w | Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_]. |
\W | Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_]. |
\s | Matches a single white space character, including space, tab, form feed, line feed, and other Unicode spaces. Equivalent to [\f\n\r\t\v\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]. For example, /\s\w*/ matches " bar" in "foo bar". |
\b | word boundary. "\baa\b.*" matches "aa bb", dose not match "aabb". |
look ahead and look behind
Lookaround | Name | What it Does |
---|---|---|
(?=foo) | Lookahead | Asserts that what immediately follows the current position in the string is foo |
(?<=foo) | Lookbehind | Asserts that what immediately precedes the current position in the string is foo |
(?!foo) | Negative Lookahead | Asserts that what immediately follows the current position in the string is not foo |
(?<!foo) | Negative Lookbehind | Asserts that what immediately precedes the current position in the string is not foo |
lazy vs greedy
type | pattern | description |
---|---|---|
greedy | .* | matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy) |
lazy | .*? | matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy) |
ref
Lookahead and Lookbehind Tutorial—Tips &Tricks
https://www.rexegg.com/regex-lookarounds.html
Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions
https://www.regular-expressions.info/lookaround.html
Regular expressions - JavaScript | MDN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Character classes - JavaScript | MDN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes
最新文章
- jenkins,dns错误log过大
- php大力力 [055节] 大力力阅读文章集锦
- Linux之重定向
- Android Touch消息传递机制探究分析
- 分布式环境下Unique ID生成方法
- lib和dll文件的区别和联系
- WPF 3D 小小小小引擎 - &#183;WPF 3D变换应用
- 第一个Delphi小程序
- 【Android Demo】通过WebService获取今日天气情况--转
- C#中的逆变和协变
- ssh自学笔记
- [20160711][在Windows下调用neven链接库]
- php里进程创建和分析
- 论JavaScript的作用域
- iptables 配置说明
- linux上安装完torch后仍报错:ImportError: No module named torch
- State management(状态管理)
- Atitit 常见每日流程日程日常工作.docx v4
- VS中常用快捷键
- Two Sum III - Data structure design LT170