I hope someone can help me with a simple RegEx for a preg_replace.

I need to replace something like this

0.00|2=399.0000

so I'm only left with the value '2'.

Would preg_replace be the most effective method to achieve this result? Another example

0.00|13=69.0000

to lift out value '13'.

Thank you for any help.

Recommended Answers

All 3 Replies

I managed to get the result with:

$value = '0.00|1=0.000';
$value = preg_replace('/\=[0-9]{1,100}\.[0-9]{1,100}/', '', $value);
$value = preg_replace('/[0-9]\.[0-9]{2}\|/', '', $value);
				
echo $value;

output: 1

Would this suffice? Or is there a way to get the result with a single preg_replace?

$value = preg_replace('/.*\|(\d+)=.*/m', '$1', $value);

Brilliant, thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.