Reputation: 11
How can I turn this into a regular expression? Basically, the version # of the software keeps updating because of new releases, and I want a way to use wild cards.
Example:
Software Pro 0.1.0.123 License Agreement
Notes:This won't work
Software Pro .* License Agreement
Thanks!
Upvotes: 1
Views: 209
Reputation: 737
The RegEx you may be looking for is:
"Software Pro [0-9\.]+ License Agreement"
This will work even if you don't know how many parts the version number can have (for instance, if in the future the developers decide they only want to show the major and minor version, e.g.: "0.1" instead of 0.1.0.123), but you do know that it consists only of digits and dots.
If the version number can have letters, you could use:
"Software Pro [0-9a-z\.]+ License Agreement"
If you are trying to find the version number and use it for something, be sure to enclose it in parentheses:
"Software Pro ([0-9a-z\.]+) License Agreement"
Upvotes: 2
Reputation: 2999
This should work for you.
haystack := "Software Pro 0.1.0.123 License Agreement"
RegExMatch(haystack, "[\d\.]+", match)
msgbox % match
[\d\.]+
matches any consecutive combination of a number
or the .
character.
Upvotes: 2
Reputation: 5291
^Software Pro ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) License Agreement$
Shorter version (if \d is supported for digits):
^Software Pro (\d+\.\d+\.\d+\.\d+) License Agreement$
It is generally best to avoid using the dot .
wildcard. The goal is to have the RegEx be as strict as possible and only match exactly what you are looking for.
Upvotes: 1