Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:35:37+00:00 2026-06-02T17:35:37+00:00

I am using Beautiful Soup to identify a specific tag and its contents. The

  • 0

I am using Beautiful Soup to identify a specific tag and its contents. The contents are html-links and I want to extract the text of these tags.

The problem is that the text is made up of different numbers according to a specific pattern. I am only interested in number such as “61993J0417” and “61991CJ0316” and I need the regexp to match both when the number has a “J” and “CJ” in the middle.

I have used this code to achieve this:

soup.find_all(text=re.compile('[6][1-2][0-9]{3}[J]|[CJ][0-9]{4}'))

The soup variable is the contents of the specific tag. This code works in 9 out of 10 cases. However, when I run this script on one of my source files, it also matches numbers such as “51987PC0716”.

I cannot understand why so I turn to you for assistance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:35:38+00:00Added an answer on June 2, 2026 at 5:35 pm

    You haven’t specified what the | applies to; by default it’s the entire regex, meaning you have asked for either

    [6][1-2][0-9]{3}[J]
    

    (which is the same thing as 6[12][0-9]{3}J) or

    CJ[0-9]{4}
    

    (not [CJ], which means “either C or J”). Use parentheses to specify what the alternatives are:

    ^6[12][0-9]{3}(J|CJ)[0-9]{4}$
    

    which is better written

    ^6[12][0-9]{3}C?J[0-9]{4}$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to extract the text from an HTML file using Python. I want
I'd like to extract the text from an HTML file using Python. I want
I am using beautifuly soup to find all href tags. links = myhtml.findAll('a', href=re.compile('????'))
I'm parsing some HTML using Beautiful Soup, and occasionally the HTML it returns includes
I'm trying to extract text and HTML from a website with Scandinavian characters using
I am using Beautiful Soup to extract 'content' from web pages. I know some
Is there an equivalent of Beautiful Soup's tag.renderContents() method in lxml? I've tried using
I am using python's beautiful stone soup to extract data from this web page
Using Beautiful Soup module, how can I get data of a div tag whose
Scraping pages using BeautifulSoup; trying to filter out links that end in ...html#comments Code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.