preg replace - PHP - Turn this string: "adc 25...123.50 xyz" into 2 variables: "25" and "123.50"? -


the title sums trying accomplish.

i have string consist of letters in alphabet or, numbers or characters ")" , "*". may include numeric string separated 3 dots "...", e.g. "25...123.50".

an example of string be:

peaches* 25...123.50 +("apples") or -(peaches*) apples* 25...123.50

now, capture numbers before , after 3 dots, end 2 variables, 25 , 123.50. trim string end string excludes number values:

peaches* +("apples") or -(peaches*) apples*

so essentially:

$string = 'peaches* 25...123.50 +("apples")'; if (preg_match("/\.\.\./", $string )) {     # how left value (could or not decimal, using .)     $from = 25;      # how right value (could or not decimal, using .)     $to = 123.50;     # how remove value "here...here" right?     $clean = preg_replace('/'.$from.'\.\.\.'.$to.'/', '', $string);     $clean = preg_replace('/  /', ' ', $string); } 

if provide me input on best way go complicated task appreciated! suggestions, advice, input, feedback or comments welcome, thank you!

this preg_match should work:

$str = 'peaches* 25...123.50 +("apples")'; if (preg_match('~(\d+(?:\.\d+)?)\.{3}(\d+(?:\.\d+)?)~', $str, $arr))    print_r($arr); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -