Main string : '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'
code of regex (OTT):
re.findall( r'^\w(.*?)O|U$', Tv_df['Features'][1])o/p : ['etflix|Prime Video|Disney Hotstar|Youtube']code of regex (Type):
re.findall(r'[a-z] \s(?:HD|SD)', Tv_df['Features'][1])o/p : ['ltra HD', 'x HD']
- The output for OTT regex is correct but the first charcter 'N' is missing.
- The output for type regex should be
Ultra HD (4K). I'm facing the same problem that is the first character 'U' is missing and the data '4K' should be extracted which is in the paranthesis.
P.S : Please find the main string above.
CodePudding user response:
- Move the
\winside the(like:^(\w.*?)O|U$to match the first letter. - You are not matching the 'U' of ultra, you can do that by adding [A-Z] at the beginning, and you have to match the things inside
( & )to get4K. You can do that by adding\s\(. ?\)to the end. So the pattern will look like this:[A-Z][a-z] \s(?:HD|SD)
