I'm trying to get a grasp on regular expressions and I came across with the one included inside the str.extract
method:
movies['year']=movies['title'].str.extract('.*((.*)).*',expand=True)
It is supposed to detect and extract whichever is in parentheses. So, if given this string: foobar (1995)
it should return 1995
. However, if I open a terminal and type the following
echo 'foobar (1995)` | grep '.*((.*)).*'
matches the whole string instead of only the content between parentheses. I assume the method is working with BRE flavor because of the parentheses scaping, and so is grep (default behavior). Also, regex matches in blue the whole string and green the year (capturing group). Am I missing something here? The regex works perfectly inside python
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…