请将“1.或者2.或者其他数字+.”到“/”的内容打印出来,需要将整个输入的内容符合要求的打印出来,遇到“/”后再次遇到“2.或者其他数字+.”继续打印,例如输入“1. distinct /dis'tigkt/ a例:Inside there was a o里面有一种明显的 2. advocate /'edvoke例:The group does not该团体不支持使用 Many experts advoc很多专家主张对小 3. consequently /'kon例:Consequently, you1因此,你开始用消 4. naval /'neival/ a淮例:The harbour is an in该港是一个重要的 Israel would presum以色列可能会解除 5. dump /damp/vt倾例:The getaway car wa那辆逃亡的小汽车 And you basically d你基本上是把它倾”,需要输出的结果为“distinct advocate consequently naval dump”,请用python编写该程序
时间: 2024-04-14 12:28:28 浏览: 19
以下是使用 Python 编写的程序实现你的要求:
```python
import re
def extract_content(text):
pattern = r"\d+\. ([^/]+)"
matches = re.findall(pattern, text)
return matches
def print_matched_content(text):
pattern = r"(\d+\. [^/]+)"
matches = re.findall(pattern, text)
for match in matches:
print(match)
input_text = "1. distinct /dis'tigkt/ a例:Inside there was a o里面有一种明显的\n" \
"2. advocate /'edvoke例:The group does not该团体不支持使用\n" \
"Many experts advoc很多专家主张对小\n" \
"3. consequently /'kon例:Consequently, you1因此,你开始用消\n" \
"4. naval /'neival/ a淮例:The harbour is an in该港是一个重要的\n" \
"Israel would presum以色列可能会解除\n" \
"5. dump /damp/vt倾例:The getaway car wa那辆逃亡的小汽车\n" \
"And you basically d你基本上是把它倾"
matched_content = extract_content(input_text)
output_text = ' '.join(matched_content)
print(output_text)
print("--------")
print_matched_content(input_text)
```
运行上述代码,会输出以下结果:
```
distinct advocate consequently naval dump
--------
1. distinct
2. advocate
3. consequently
4. naval
5. dump
```