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

  • Home
  • SEARCH
  • 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 9228577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:32+00:00 2026-06-18T05:21:32+00:00

I have this regex: a_list = re.compile(r’\(\d+\)\s*\n’).split(content) Its working great to match lines with

  • 0

I have this regex:

a_list = re.compile(r'\(\d+\)\s*\n').split(content)

Its working great to match lines with (number) in the end, however I need to get that number as well.

How do I do that?

Thanks.

  • 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-18T05:21:33+00:00Added an answer on June 18, 2026 at 5:21 am

    As described on the regular expressions documentation for Python, the split method on a regex splits the string that’s being worked on by all matches of the regex pattern. Right now, your regex is capturing all matches that have a number at the end and splitting the string on that match. So a_list contains everything in every line containing a number except for the number and its surrounding parentheses (and optional space).

    Assuming that you don’t want to split all newlines (by just making your regex '\n'), you can use a negative lookbehind to only capture matches to the regex where another regex is preceding the match, but not include the matches for that second regex in the results. The format for that is (?<!x)y where all instances of y will be captured if and only if the x phrase is proceeding it, but the x phrase will not be included along with it.

    The only problem with using a negative lookbehind in this situation is that it requires a fixed number of characters to be matched, but you have \d+, which could be any number of characters. Fortunately, you can just drop the + as well as the leading \( so that you check to see if there is at least one digit preceding your regex pattern so that we’re just checking for \d\); which works because we don’t care if the line ends with (10000) or (1).

    Unfortunately, this would cause lines like (abc123) to be captured, which doesn’t match the \(\d+\) regex you originally had. If you need to ensure that lines end with parentheses that only contain a multi-digit a number, you’ll probably have to use multiple regex operations.

    That does leave the problem of \s*, so you have two options. You can either create an or expression if you know how many spaces will be at the end, e.g. (\d|\d\s), or you can just include the \s* in the match with the newline character, thus removing any trailing whitespace as well.

    Assuming you take the latter option, your example would look like (?<!\d\))\s*\n, which will result in a_list containing all lines that include a number at the end being included, along with the number itself (and its surrounding parentheses).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regex that checks for a 5 digit number ^\d{5}$ How do
I have the following data: abc def; ghi. This regex will match: ([a-z0-9A-ZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ ]*)\W
Is this Regex correct if I have to match a string which is atleast
Possible Duplicate: RegEx match open tags except XHTML self-contained tags I have this list
I have this regex /^([a-z0-9]([a-z0-9-]*[a-z0-9])*){1,60}\.cz$/i . Rules: Domain Name may contain only characters [a-z,0-9,-]
I have this regex: private static final String SPACE_PATH_REGEX =[a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+; I check if my
Is there any way to have this: [one[two]][three] And extract this with a regex?
I have a problem with a difficult regex. I have this expression to detect
Using mootools I have a regex like this: new RegExp('^([^\\D'+ separator +']+)(\\d{2})'); In a
i have this string This is a <143>sample</143> regex <143>pa<665>t</665>tern</143> selection <143>by</143> tags in

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.