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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:36:37+00:00 2026-06-13T11:36:37+00:00

Assuming I have the following string: thestring = 1) My Favorite Pokemon Charizard *22.00

  • 0

Assuming I have the following string:

thestring = "1) My Favorite Pokemon Charizard *22.00 MP* [Pre-Avatar Mode Cost: 15.75 MP] [Post-Avatar Mode Cost: 6.250 MP]"

Some other samples could be:

thestring = "1) My Favorite Pokemon Mew *1 MP* [Pre-Avatar Mode Cost: 0.5 MP] [Post-Avatar Mode Cost: 0.5 MP]"

thestring = "1) My Favorite Pokemon Pikachu *6.25 MP* [Pre-Avatar Mode Cost: 5 MP]; [Post-Avatar Mode Cost: 1.25 MP]"

(colon for the third case is intentional)

How to best extract the values of “Pre-Casting Cost” and “Post-Avatar Mode Cost”? I hear regex, but also string.find methods, but am not sure what is the best way to accomplish this. Note that there though the “Pre-Avatar Mode Cost” may be 15.75 MP, but could also depending on variety, could also be 15.752 or contain multiple decimal places. Syntax is appreciated.

UPDATE:

I am using Python 2.7. Closest answer is the following:

m = re.match('\[Pre-Avatar Mode Cost: (?P<precost>\d(\.\d*){0,1}) MP\] \[Post-Avatar Mode Cost: (?P<postcost>\d(\.\d*){0,1}) MP\]', '1) My Favorite Pokemon Mew *1 MP* [Pre-Avatar Mode Cost: 0.5 MP] [Post-Avatar Mode Cost: 0.5 MP]')

Though it appears to not actually match properly resulting in m results in a “Nonetype”due to no matches.

I made a slight change by using the following:

m = re.match('(.*)\[.*(?P<precost>\d+(\.\d*){0,1}).*\].*\[.*(?P<postcost>\d+(\.\d*){0,1}).*\]', '1) My Favorite Pokemon Mew *1 MP* [Pre-Avatar Mode Cost: 0.5 MP] [Post-Avatar Mode Cost: 0.5 MP]')

Though it appears that precost and postcost are both equal to “5”. Any idea what the issue may be with the regular expression?

  • 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-13T11:36:38+00:00Added an answer on June 13, 2026 at 11:36 am

    I think a regex is the best bet for this:

    pattern = re.compile(r"\[.*?([0-9]+(?:\.[0-9]+)?).*?\]")
    pre, post = [float(x) for x in re.findall(pattern, thestring)]
    

    That should work regardless of the number (or lack) of decimal places.

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

Sidebar

Related Questions

Assuming I have the following strings: string str1 = Hello World!; string str2 =
Assuming the message argument is a string, I have the following snippet: users.each do
Assuming I have the following list: IList<string> list = new List<string>(); list.Add(Mouse); list.Add(Dinner); list.Add(House);
I have some thread-related questions, assuming the following code. Please ignore the possible inefficiency
assuming I have the following array: views = [ { :user_id => 1, :viewed_at
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
Assuming you have the following XML: <?xml version=1.0 encoding=utf-8?> <content> <info> <media> <image> <info>
I have the following situation. Assuming there are 3 systems: A,B,C and A is
In a java app, assuming I have option of choosing the following comparison methods
Is there a cleaner way to do the following, assuming that I have 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.