我需要匹配Measured at X;2023/03/10 03:15:18, 00:00:16 [999] ¥;2023/03/10 03:15:35, 00:00:16 [999] Align. Decent. Free:X = 0. 5228(um) Free:¥ = 0.3051 (um) Free:Z = -0.2269(um) Align. Tilt Freeza = -0.1392(min) Free:b = -0.3905(min) — Lock:¢ = 0. 0000(min)中的Free:¥ = 0.3051 (um)如何用re匹配
时间: 2023-05-31 17:06:36 浏览: 141
Diode-pumped high-efficiency Tm:YLF laser at room temperature
可以使用以下正则表达式匹配:
```python
import re
text = "Measured at X;2023/03/10 03:15:18, 00:00:16 [999] ¥;2023/03/10 03:15:35, 00:00:16 [999] Align. Decent. Free:X = 0. 5228(um) Free:¥ = 0.3051 (um) Free:Z = -0.2269(um) Align. Tilt Freeza = -0.1392(min) Free:b = -0.3905(min) — Lock:¢ = 0. 0000(min)"
pattern = r"Free:¥ = (\d+\.\d+) \(um\)"
match = re.search(pattern, text)
if match:
print(match.group(1))
```
输出结果为:
```
0.3051
```
解释一下正则表达式:
- `Free:¥ = ` 匹配字符串 "Free:¥ = "
- `(\d+\.\d+)` 匹配一个或多个数字和一个小数点,再匹配一个或多个数字,使用括号将结果捕获为一个组
- `\(um\)` 匹配字符串 "(um)",需要使用反斜杠对括号进行转义
阅读全文