regex
parent
d8639390da
commit
c9585666b9
|
@ -4,8 +4,12 @@ Read [Syntax](https://github.com/google/re2/wiki/Syntax).
|
|||
|
||||
Read [Golang-Regex-Tutorial](https://github.com/StefanSchroeder/Golang-Regex-Tutorial).
|
||||
|
||||
Play with [Regex101](https://regex101.com/).
|
||||
|
||||
## Basic
|
||||
|
||||
| regex | meaning |
|
||||
| -------- | ----------------------------------------- |
|
||||
| ------------ | ----------------------------------------- |
|
||||
| `.` | any character, default not including `\n` |
|
||||
| `[xy]` | `x` or `y` character |
|
||||
| `[^xy]` | not `x` and `y` character |
|
||||
|
@ -21,9 +25,6 @@ Read [Golang-Regex-Tutorial](https://github.com/StefanSchroeder/Golang-Regex-Tut
|
|||
| `\D` | not digits |
|
||||
| `\s` | whitespace |
|
||||
| `\S` | not whitespace |
|
||||
|
||||
| advanced regex | meaning |
|
||||
| -------------- | ----------------------------------- |
|
||||
| `(foo)` | numbered capturing group (submatch) |
|
||||
| `(?:foo)` | non capturing group |
|
||||
| `(?:x`\|`y)` | `x` or `y` expression wrap in `()` |
|
||||
|
@ -33,3 +34,23 @@ Read [Golang-Regex-Tutorial](https://github.com/StefanSchroeder/Golang-Regex-Tut
|
|||
| ---- | ---------------- |
|
||||
| `i` | case-insensitive |
|
||||
| `s` | `.` match `\n` |
|
||||
|
||||
## Example
|
||||
|
||||
```regex
|
||||
(?i)hello\sfoo
|
||||
|
||||
match: Hello Foo
|
||||
match: heLLo fOO
|
||||
```
|
||||
|
||||
```regex
|
||||
hello\s(.+)
|
||||
|
||||
match: hello foo
|
||||
group 1: foo
|
||||
|
||||
|
||||
match: hello bar
|
||||
group 1: bar
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue