php - regular expression match, Need to match both number -
how match both number 123,340.00 , 1.9e10? have tried regex below
^-?\d+(,)*(\d+\.(\d+e?)) but matches 123,340.00, looking match both number. idea? please.
note: have tried @ online regex tool https://regex101.com
you should allow digits after e @ least. also, ,* matches 0 or more commas, , think should allow comma + digits groups.
i suggest using
'~^-?\d+(?:,\d+)*(?:\.\d+)?(?:e[+-]?\d+)?$~i' see regex demo
pattern explanation:
^- start of sting-?- optional-(you may use[-+]?match plus or minus)\d+- 1 or more digits(?:,\d+)*- 0 or more sequences of comma + 1 or more digits(?:\.\d+)?- optional decimal part, dot , 1+ digits(?:e[+-]?\d+)?- optional exponent part,e, optional minus or plus, , 1+ digits$- end of string.
note ~i modifier used match both e , e.
Comments
Post a Comment