How to pick up all numbers from string

xpedobearx

I have a string that looks like abc,5,7 from which I want to get the numbers.

I've come up with this:

^(?<prefix>[a-z]+)(,(?<num1>\d+?))?(,(?<num2>\d+?))?$#i

but it will only work with 2 numbers, and my string has a variable number of numbers. I don't know how to change the regex to account for that. Help please

Lemon Kazi

You can try this

<?php
$string = "abc,5,7";
$int = intval(preg_replace('/[^0-9]+/', '', $string), 10);
echo $int;
?>

Also you can Use this regular expression !\d!

<?php
$string = "abc,5,7";
preg_match_all('!\d!', $string, $matches);
echo (int)implode('',$matches[0]);

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pick up all data into hive from subdirectories

From Dev

How do I modify this REGEX to pick up all dates in the test string

From Dev

Android - How to pick numbers from a generated list?

From Dev

Pick up two numbers from an array so that the sum is a constant

From Dev

How to pick capital letters from a Swift string?

From Dev

How can I pick from this string?

From Dev

How to pick up a sprite?

From Dev

Joda-Time, How to pick up format for string parsing?

From Dev

How to extract number from string in BATCH and get total of all numbers?

From Dev

how to remove all characters from string and leave numbers only in dataframe?

From Dev

How to pick out individual numbers from the text file?

From Dev

How to pick up a random key from a table in Lua?

From Dev

How to pick up a random key from a table in Lua?

From Dev

How to pick up data- * in the parent from the child

From Dev

How to pick up the earliest timestamp date from the RDD in scala

From Dev

How to pick a random string from string array only once

From Dev

How to randomly pick a number of combinations from all the combinations efficiently

From Dev

How can I pick out the odd numbers and even numbers from a given array and then store them in another array?

From Dev

How can I pick out the odd numbers and even numbers from a given array and then store them in another array?

From Dev

Get all whole and decimal numbers from string

From Dev

Trying to remove all numbers from a string in C

From Dev

Find and extract all numbers from the String

From Dev

extract all the numbers from a string in a javascript

From Dev

Apply math to all numbers from a string?

From Dev

MATLAB reading all numbers from a string

From Dev

RegEx extract all real numbers from a string

From Dev

Remove all numbers and "{" from a String Array

From Dev

Get all numbers from long string

From Dev

How to pick specific part from a string in XSLT2.0

Related Related

  1. 1

    How to pick up all data into hive from subdirectories

  2. 2

    How do I modify this REGEX to pick up all dates in the test string

  3. 3

    Android - How to pick numbers from a generated list?

  4. 4

    Pick up two numbers from an array so that the sum is a constant

  5. 5

    How to pick capital letters from a Swift string?

  6. 6

    How can I pick from this string?

  7. 7

    How to pick up a sprite?

  8. 8

    Joda-Time, How to pick up format for string parsing?

  9. 9

    How to extract number from string in BATCH and get total of all numbers?

  10. 10

    how to remove all characters from string and leave numbers only in dataframe?

  11. 11

    How to pick out individual numbers from the text file?

  12. 12

    How to pick up a random key from a table in Lua?

  13. 13

    How to pick up a random key from a table in Lua?

  14. 14

    How to pick up data- * in the parent from the child

  15. 15

    How to pick up the earliest timestamp date from the RDD in scala

  16. 16

    How to pick a random string from string array only once

  17. 17

    How to randomly pick a number of combinations from all the combinations efficiently

  18. 18

    How can I pick out the odd numbers and even numbers from a given array and then store them in another array?

  19. 19

    How can I pick out the odd numbers and even numbers from a given array and then store them in another array?

  20. 20

    Get all whole and decimal numbers from string

  21. 21

    Trying to remove all numbers from a string in C

  22. 22

    Find and extract all numbers from the String

  23. 23

    extract all the numbers from a string in a javascript

  24. 24

    Apply math to all numbers from a string?

  25. 25

    MATLAB reading all numbers from a string

  26. 26

    RegEx extract all real numbers from a string

  27. 27

    Remove all numbers and "{" from a String Array

  28. 28

    Get all numbers from long string

  29. 29

    How to pick specific part from a string in XSLT2.0

HotTag

Archive