I use Beautiful Soup to define a specific tag and its contents. The content is html links and I want to extract the text of these tags.
The problem is that the text consists of different numbers according to a specific pattern. I am only interested in a number, for example “61993J0417” and “61991CJ0316”, and I need the regular expression to match when the number has “J” and “CJ” in the middle.
I used this code for this:
soup.find_all(text=re.compile('[6][1-2][0-9]{3}[J]|[CJ][0-9]{4}'))
A soup variable is the contents of a particular tag. This code works in 9 out of 10 cases. However, when I run this script in one of my source files, it also matches numbers such as "51987PC0716".
I do not understand why I am turning to you for help.
source
share