I need some help creating regular expressions to pick information out of a file. I am using php preg_match to do it and am trying to get information that looks like the following:
ex.
19-Aug-2013 //The date will always be in the format.
and a number like this
303.00
The file I am trying to get this information from is the body of a mime type email.
I only need these two types of specific information.
Try this as a whole:
preg_match_all('/(\\d{2}-\\w{3}-\\d{4}|\\d+\\.\\d{1,2})/', $file, $matches);
\\d{2}-\\w{3}-\\d{4}
: Get the date
\\d+\\.\\d{1,2}
: Get the float
By using preg_match_all
you return all found matches in all the haystack. preg_match
only matches the first occurance.
For the date you can use:
[0-9]{2}-[a-z]{3}-[0-9]{4}
For the number:
[0-9]+\.[0-9]{2}
With no specific input is hard to come up with a better regex at the moment...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.