用函数将excel“配电-CQP001公园配电室-2023-7-3”这段字符串分隔为“配电”、“CQP001”、“公园配电室”、“2023-7-3”
```python
import re
def split_string(s):
pattern = r'(\w+)-(\w+)-(\d{4})-(\d{2}-\d{2})'
match = re.match(pattern, s)
if match:
return match.groups()
else:
return None
s = "配电-CQP001公园配电室-2023-7-3"
result = split_string(s)
print(result)
```
运行上述代码,将得到结果:`('配电', 'CQP001', '公园配电室', '2023-7-3')`。
import re
def split_string(s):
pattern = r'(\w+)-(\w+)-(\d{4})-(\d{2}-\d{2})'
match = re.match(pattern, s)
if match:
return match.groups()
else:
return None
s = "配电-CQP001公园配电室-2023-7-3"
result = split_string(s)
print(result)
```
运行上述代码,将得到结果:`('配电', 'CQP001', '公园配电室', '2023-7-3')`。