Hi does anyone know why this code returns a “No” and the other one returns a “Yes”?
JavaScript
x
18
18
1
import re
2
b="@gmail.com"
3
x=re.findall(r"Bgmail",b)
4
if x:
5
print("Yes")
6
else:
7
print("No") # <<<
8
9
10
11
import re
12
b="agmail.com"
13
x=re.findall(r"Bgmail",b)
14
if x:
15
print("Yes") # <<<
16
else:
17
print("No")
18
Advertisement
Answer
As b
is word boundary, B
is the opposite
Your regex "Bgmail"
ask for :
gmail
word- with NO word boundary before it
@gmail.com ^^ there is a word boundary between these 2 chars, so regex don't match agmail.com ^^ there is NO word boundary between these 2 chars, so regex match