Skip to content

Commit a4d054c

Browse files
committed
Add demo regex
1 parent 3e9d6ea commit a4d054c

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
|| 内容 | 资料 | 代码 |
77
|---|---|---|---|
88
| 1 | 使用Python编写神经网络 | [课件](notes/L1-使用python编写神经网络.pdf) | [factorial-relu](code/l1-factorial-relu.py), [factorial-sigmoid](code/l1-factorial-sigmoid.py) |
9-
| 2 | Python程序的解析和运行 | [课件](notes/L2-Python程序的解析和运行.pdf) | [relu](code/l2-relu.py), [pytool](code/l2-pytool.py) |
9+
| 2 | Python程序的解析和运行 | [课件](notes/L2-Python程序的解析和运行.pdf) | [regex](code/l2-regex.py), [pytool](code/l2-pytool.py), [relu](code/l2-relu.py) |
1010
| 3 | Python与Native Code交互 | | |
1111
| 4 | Python多线程 | | |
1212
| 5 | 课堂反转 | |

code/l2-regex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import re
2+
3+
pattern_name = r'[A-Za-z_][A-Za-z0-9_]*'
4+
pattern_number = r'\d+(?:\.\d+)?'
5+
6+
examples = ['ABC', 'aBC', 'x = 123', 'var1 = 3.14']
7+
8+
for text in examples:
9+
names = re.findall(pattern_name, text)
10+
numbers = re.findall(pattern_number, text)
11+
12+
print(f"Text: {text!r}")
13+
print(f"Names: {names}")
14+
print(f"Numbers: {numbers}")
15+
print("-" * 40)

0 commit comments

Comments
 (0)