, asked
Views : 2

How does \B regular expression work in Python?

How does \B regular expression work in Python?

1 Answer
Rajendra Dharmkar

The word boundary \b matches positions where one side is a word character (usually a letter, digit or underscore)

\B matches all positions where \b doesn't match.

The following code shows how regexpr \B works

import re
result = re.findall(r'\Bcat', 'certificate')
result2 = re.findall(r'\Bcat', 'tomcat')
result3 = re.findall(r'\Bcat', 'catfish')
print result, result2,result3

This gives the output

['cat'] ['cat'] []

Advertisements
Related Questions