不获取字符串的第一个字符并使用正则表达式获取括号中的数据
Not getting the first character of the string and get the data which is in a parenthesis using regex
主字符串:'Netflix|Prime Video|Disney+Hotstar|YoutubeOperating System: AndroidUltra HD (4K) 3840 x 2160 Pixels30 W Speaker Output60 Hz Refresh Rate3 x HDMI | 2 x USBA+ Grade1 Year'
正则表达式 (OTT) 代码:re.findall( r'^\w(.*?)O|U$', Tv_df['Features'][1])
o/p : ['etflix|Prime Video|Disney+Hotstar|Youtube']
正则表达式代码(类型):re.findall(r'[a-z]+\s(?:HD|SD)', Tv_df['Features'][1])
o/p : ['ltra HD', 'x HD']
- OTT 正则表达式的输出是正确的,但缺少第一个字符 'N'。
- 正则表达式类型的输出应该是
Ultra HD (4K)
。我面临同样的问题,即缺少第一个字符 'U' 并且应该提取括号中的数据“4K”。
P.S : 请找出上面的主串
- 将
\w
移动到 (
内,如:^(\w.*?)O|U$
以匹配第一个字母。
- 你匹配的不是ultra的'U',你可以在开头加上[A-Z],而且你要匹配
( & )
里面的东西才能得到4K
。您可以通过在末尾添加 \s\(.+?\)
来做到这一点。所以模式看起来像这样:[A-Z][a-z]+\s(?:HD|SD)
主字符串:'Netflix|Prime Video|Disney+Hotstar|YoutubeOperating System: AndroidUltra HD (4K) 3840 x 2160 Pixels30 W Speaker Output60 Hz Refresh Rate3 x HDMI | 2 x USBA+ Grade1 Year'
正则表达式 (OTT) 代码:
re.findall( r'^\w(.*?)O|U$', Tv_df['Features'][1])
o/p : ['etflix|Prime Video|Disney+Hotstar|Youtube']正则表达式代码(类型):
re.findall(r'[a-z]+\s(?:HD|SD)', Tv_df['Features'][1])
o/p : ['ltra HD', 'x HD']
- OTT 正则表达式的输出是正确的,但缺少第一个字符 'N'。
- 正则表达式类型的输出应该是
Ultra HD (4K)
。我面临同样的问题,即缺少第一个字符 'U' 并且应该提取括号中的数据“4K”。
P.S : 请找出上面的主串
- 将
\w
移动到(
内,如:^(\w.*?)O|U$
以匹配第一个字母。 - 你匹配的不是ultra的'U',你可以在开头加上[A-Z],而且你要匹配
( & )
里面的东西才能得到4K
。您可以通过在末尾添加\s\(.+?\)
来做到这一点。所以模式看起来像这样:[A-Z][a-z]+\s(?:HD|SD)