超方便!
未來一定會用到的字串處理技能
語法 | 意義 |
---|---|
a-z | 字元 a 到 z |
A-Z | 字元 A 到 Z |
0-9 | 字元 0 到 9 |
語法 | 意義 |
---|---|
[abc] | 匹配 \(a\) 或 \(b\) 或 \(c\) 字元 |
[^abc ] | 匹配不含 \(a、b、c\) 的字元 |
{m} | 重複 \(m\) 次 |
{m, n} | 重複 \(m\) 次或 \(m+1\) 次或\(... n\)次 |
* | 重複 \(0\) 次以上 |
+ | 重複 \(1\) 次以上 |
語法 | 意義 |
---|---|
? | 可選字元 |
. | 任意字元 |
\. | . |
\d | [0-9] |
\w | [A-Za-z0-9] |
\s | 空白字元 |
語法 | 意義 |
---|---|
^…$ | 開始和結束 |
(abc) | abc 為群組 |
(a(bc)) | bc 為子群組 |
( abc | def) | 匹配 abc 或 def 字串 |
(建議至 RegexOne 上練習效果更佳)
以下提供幾種範例解,供讀者快速理解用。
Match abcdefg
Match abcde
Match abc
Ans: "[a-z]+"、"\w+"
Match abc123xyz
Match var g = 123;
Match define "123"
Ans: "[a-z0-9 =";]+"、"[\w" =;]+"
Match cat.
Match 896.
Match ?=+.
Skip abc1
Ans: "...\."
Match can
Match man
Match fan
Skip dan
Skip ran
Skip pan
Ans: "[cmf]an"、"[^drp]an"
Match wazzzzzup
Match wazzzup
Skip wazup
Ans: "waz{2,}up"、"waz{3,5}up"
Match aaaabcc
Match aabbbbc
Match aacc
Skip a
Ans: "a{2,4}b{0,4}c{1,2}"、"aa+b*c+"
Match 1 file found?
Match 2 files found?
Match 24 files found?
Skip No files found.
Ans: "\d+ files? found\?"
Match Mission: successful
Skip Last Mission: unsuccessful
Skip Next Mission: successful upon capture of target
Ans: "^Mission: successful$"
Match I love cats
Match I love dogs
Skip I love logs
Skip I love cogs
Ans: "I love (cats|dogs)"
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing