I try to use the same regular expression pattern in Python and Bash, but it is not working in the same way, when the pattern has a parenthesis in it. For exemple, I try to look at every "the" in an article. Here is the pattern
"(^|[^a-zA-Z])[Tt]he($|[^a-zA-Z])"
In Bash, I write
egrep --color "(^|[^a-zA-Z])[Tt]he($|[^a-zA-Z])" Untitled.txt
But in Python, if I do this:
pattern=re.compile(r"(^|[^a-zA-Z])[Tt]he($|[^a-zA-Z])")
re.findall(pattern, text)
I will have the result of what it matches only inside the parenthesis, while I want the "the".
If I want to have the same effet like Bash, I have to repeat:
pattern=re.compile(r"^[Tt]he|[^a-zA-Z][Tt]he|[Tt]he$|[Tt]he[^a-zA-Z]")
So, my question is, is there any difference about parenthesis in Python and in Bash ?