Regex to find $ amount and % amount in a string
Posted: Fri Dec 09, 2016 10:04 am
Hi,
I am working a requirement where I need to extract the $ amount or % amount from a string. I have been able to extract dollar amount successfully using the following regex pattern
$pattern = '/\$[0-9]*\.{0,1}[0-9]+/';
I still however need help with finding % amount using the same regex. Can someone please help.
Example:
5% Off Your Order --> Need to get 5% from this
5.25% Off All Orders --> Need to get 5.25% from this
$10 Off Orders Over $100 --> Need to get $10, $100
Can someone please help me with the Regex.
I am working a requirement where I need to extract the $ amount or % amount from a string. I have been able to extract dollar amount successfully using the following regex pattern
$pattern = '/\$[0-9]*\.{0,1}[0-9]+/';
I still however need help with finding % amount using the same regex. Can someone please help.
Example:
5% Off Your Order --> Need to get 5% from this
5.25% Off All Orders --> Need to get 5.25% from this
$10 Off Orders Over $100 --> Need to get $10, $100
Can someone please help me with the Regex.