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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:13:43+00:00 2026-05-27T15:13:43+00:00

I have a sample string <alpha.Customer[cus_Y4o9qMEZAugtnW] active_card=<alpha.AlphaObject[card] …>, created=1324336085, description=’Customer for My Test App’,

  • 0

I have a sample string <alpha.Customer[cus_Y4o9qMEZAugtnW] active_card=<alpha.AlphaObject[card] ...>, created=1324336085, description='Customer for My Test App', livemode=False>

I only want the value cus_Y4o9qMEZAugtnW and NOT card (which is inside another [])

How could I do it in easiest possible way in Python?
Maybe by using RegEx (which I am not good at)?

  • 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-05-27T15:13:43+00:00Added an answer on May 27, 2026 at 3:13 pm

    How about:

    import re
    
    s = "alpha.Customer[cus_Y4o9qMEZAugtnW] ..."
    m = re.search(r"\[([A-Za-z0-9_]+)\]", s)
    print m.group(1)
    

    For me this prints:

    cus_Y4o9qMEZAugtnW
    

    Note that the call to re.search(...) finds the first match to the regular expression, so it doesn’t find the [card] unless you repeat the search a second time.

    Edit: The regular expression here is a python raw string literal, which basically means the backslashes are not treated as special characters and are passed through to the re.search() method unchanged. The parts of the regular expression are:

    1. \[ matches a literal [ character
    2. ( begins a new group
    3. [A-Za-z0-9_] is a character set matching any letter (capital or lower case), digit or underscore
    4. + matches the preceding element (the character set) one or more times.
    5. ) ends the group
    6. \] matches a literal ] character

    Edit: As D K has pointed out, the regular expression could be simplified to:

    m = re.search(r"\[(\w+)\]", s)
    

    since the \w is a special sequence which means the same thing as [a-zA-Z0-9_] depending on the re.LOCALE and re.UNICODE settings.

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

Sidebar

Related Questions

I have sample java code like below. String testEfdDirectoryPath=D:\\test; String efdExecutable = test.cmd; File
I have this string Sample Text <test@test.com> and this string test@test.com and I'm trying
I have a sample string: <num>1.</num> <Ref>véase anomalía de Ebstein</Ref> <num>2.</num> <Ref>-> vascularización</Ref> I
I have this sample string where I would like to replace the star with
I have the following formatted sample string: == header == information about things ==headeragain==
I have the following String Sample however in some occurences there may be one
Assume I have a class that looks like this: class Sample { public string
Say you have a string 3.4564. A sample set in the database has these
i have this string This is a <143>sample</143> regex <143>pa<665>t</665>tern</143> selection <143>by</143> tags in
I have this sample string : &Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office

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.