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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:44:52+00:00 2026-06-01T15:44:52+00:00

In this program I am trying to make, I have an expression (such as

  • 0

In this program I am trying to make, I have an expression (such as “I=23mm”, or “H=4V”) and I am trying to extract the 23 (or the 4) out of it, so that I can turn it into an integer.

The problem I keep running into is that since the expression I am trying to take the numbers out of is 1 word, I cannot use split() or anything.

One example I saw but wouldnt work was –

I="I=2.7A"
[int(s) for s in I.split() if s.isdigit()]

This wouldnt work because it only takes the numbers are are delimited by spaces. If there was a number in the word int078vert, it wouldnt extract it. Also, mine doesnt have spaces to delimit.

I tried one that looked like this,

re.findall("\d+.\d+", "Amps= 1.4 I")

but it didnt work either, because the number that is being passed is not always 2 digits. It could be something like 5, or something like 13.6.

What code do I need to write so that if I pass a string, such as

I="I=2.4A"

or

I="A=3V"

So that I can extract only the number out of this string? (and do operations on it)? There are no spaces or other constant chars that I can delimit by.

  • 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-01T15:44:53+00:00Added an answer on June 1, 2026 at 3:44 pm
    >>> import re
    >>> I = "I=2.7A"
    >>> s = re.search(r"\d+(\.\d+)?", I)
    >>> s.group(0)
    '2.7'
    >>> I = "A=3V"
    >>> s = re.search(r"\d+(\.\d+)?", I)
    >>> s.group(0)
    '3'
    >>> I = "I=2.723A"
    >>> s = re.search(r"\d+(\.\d+)?", I)
    >>> s.group(0)
    '2.723'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i'm trying to make a program that can find how many pixels of
I'm currently trying to make a program that conjugates verbs into Spanish. I've created
I am trying to make this program so that the only time that there
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
Hi iam new to c++ and iam trying out this vector program and i
i am new kernel programming.i have been trying to load this driver program for
I'm trying to make a program in C# that monitors the processor time of
Here's what I'm trying to accomplish with this program: a recursive method that checks
I'm trying to automate input into a command line C program (which I have

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.