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 9266333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:17:37+00:00 2026-06-18T14:17:37+00:00

I am using python’s re.findall method to find occurrence of certain string value in

  • 0

I am using python’s re.findall method to find occurrence of certain string value in Input string.
e.g. From search in ‘ABCdef’ string, I have two search requirements.

  1. Find string starting from Single Capital letter.
  2. After 1 find string that contains all capital letter.

e.g. input string and expected output will be:

  • 'USA' -- output: ['USA']
  • 'BObama' -- output: ['B', 'Obama']
  • 'Institute20CSE' -- output: ['Institute', '20', 'CSE']

So My expectation from

>>> matched_value_list = re.findall ( '[A-Z][a-z]+|[A-Z]+' , 'ABCdef' )

is to return ['AB', 'Cdef'].

But which does Not seems to be happening. What I get is ['ABC'] as return value, which matches later part of regex with full string.

So Is there any way we can ignore found matches. So that once 'Cdef' is matched with '[A-Z][a-z]+'. second part of regex (i.e. '[A-Z]+') only matches with remaining string 'AB'?

  • 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-18T14:17:39+00:00Added an answer on June 18, 2026 at 2:17 pm

    First you need to match AB, which is followed by an Uppercase alphabet and then a lowercase alphabet. or is at the end of the string. For that you can use look-ahead.

    Then you need to match an Uppercase alphabet C, followed by multiple lowercase alphabets def.

    So, you can use this pattern:

    >>> s = "ABCdef"
    >>> re.findall("([A-Z]+(?=[A-Z][a-z]|$)|[A-Z][a-z]+)", s)
    ['AB', 'Cdef']
    
    >>> re.findall("([A-Z]+(?=[A-Z][a-z]|$)|[A-Z][a-z]+)", 'MumABXYZCdefXYZAbc')
    ['Mum', 'ABXYZ', 'Cdef', 'XYZ', 'Abc']
    

    As pointed out in comment by @sotapme, you can also modify the above regex to: –

    "([A-Z]+(?=[A-Z]|$)|[A-Z][a-z]+|\d+)"
    

    Added \d+ since you also want to match digit as in one of your example. Also, he removed [a-z] part from the first part of look-ahead. That works because, + quantifier on the [A-Z] outside is greedy by default, so, it will automatically match maximum string, and will stop only before the last upper case alphabet.

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

Sidebar

Related Questions

When using Python is it possible that a dict can have a value that
using python 2.6.5 and python-ldap 2.3.10, I have the following problem: Under certain circumstances
Using python I have to retrieve value of time and date of an event
When using Python's super() to do method chaining, you have to explicitly specify your
Using Python v2, is there a way to ignore a value in a string
Using Python v2, I have the user entering an amount into a string as
Using Python and the NLTK I have written a regex to find words with
Using Python, how would I go about reading in (be from a string, file
Using Python I would like to find the date object for last Wednesday. I
Using Python I want to randomly rearrange sections of a string based on a

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.