I’m trying to retrieve only the version number out of a string, but the strings aren’t formatted in a specific. For example, the strings may be written in (but not limited to) any of the following formats
- “Angry Birds v2.0.0”
- “Angry Birds 2.0.0”
- “v1.25”
- “Version: 1.3”
- ” 2.0.1 “
I need to create a php function that will return ONLY the version number (ex: “2.0.0” from each of these strings. Would using regular expressions be useful at all in this task? If so, what built in PCRE (perl compatible regular expressions) PHP functions should I make use of?
Please keep in mind I have very little understanding of regular expressions. Thanks!
Try this:
RESULT:
@Tim Pietzcker:
Your code will fail when project’s name alone will contain a digit, for example "Dots4You v3.15" will catch "4" as a version. Version should contain at least 2 digits and 1 dot.