-3

I have the following string:

[(33, 165) (1423, 254)]

How can I bring the 4 numbers into an Array? I tried with regex so far.

Result should be an array containing 33,165,1423,254.

I can use a PHP and Javascript solution.

domi771
  • 450
  • 1
  • 9
  • 21

2 Answers2

1

There you go:

<?php

$string = '[(33, 165) (1423, 254)]';
$regex = '~\d+~';
preg_match_all($regex, $string, $numbers);
print_r($numbers);
?>
Jan
  • 42,290
  • 8
  • 54
  • 79
1

I don't know for what you are using this and why you require this. But if [(33, 165) (1423, 254)] is a string, below php code can be used to create an array of the numbers in this string.

<?php

$string = "[(33, 165) (1423, 254)]";

$string = str_replace([" ","(","[","]"], "", $string);
$string = str_replace(")", ",", $string);
$array = explode(",", $string);

print_r($array);

OUTPUT

Array ( [0] => 33 [1] => 165 [2] => 1423 [3] => 254)
Arun D
  • 2,369
  • 5
  • 27
  • 39