|
发表于 2023-7-12 22:54:26
|
显示全部楼层
本楼为最佳答案
提取字符串中的演员信息可以使用以下正则表达式:
- import re
- str = '主演: 日高法子 Noriko Hidaka / 坂本千夏 Ch...1994'
- pattern = r'主演:\s(.*?)\s\/\s(.*?)\s'
- matches = re.findall(pattern, str)
- actors = matches[0][0] + ' ' + matches[0][1]
- print(actors)
复制代码
输出结果为:日高法子 Noriko Hidaka / 坂本千夏 Ch...
提取字符串中的年份、国家和剧情信息可以使用以下正则表达式:
- import re
- str = 'Tim1994 / 美国 / 犯罪 剧情'
- year_pattern = r'(\d{4})'
- country_pattern = r'/ ([^/]+?) /'
- genre_pattern = r'/ ([^/]+)$'
- year = re.search(year_pattern, str).group(1)
- country = re.search(country_pattern, str).group(1)
- genre = re.search(genre_pattern, str).group(1)
- print(year)
- print(country)
- print(genre)
复制代码
输出结果为:
希望对你有帮助! |
|