Click here to Skip to main content
15,917,321 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
My english is a little bit unpolished, so please be patient with my grammatics.

I have the following regex's to find a version number in a string, for example this user agent: "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14",

1. (\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)
2. (\*|(\d+(\.(\d+(\.(\d+|\*))?|\*))?))

which I believe means (and correct me where I'm wrong):
1: the first 3 groups means "up to 3 digit(s)-dot", but in the fourth, what does the "\*" do?
2: again, what does the "\*" do?
Posted
Updated 3-Nov-13 21:05pm
v4

1 solution

If you aren't sure, then the best thing to do is to get a copy of Expresso: http://www.ultrapico.com/expresso.htm[^]
It's free, and it explains, helps you create and tests Regexes - I use it all the time and really wish I'd written it. (And I wish it came in an Android version, too).

"\*"in a Regex is a literal "*" - so
(\*|\d+)
matches a single star or one-or-more digits.
 
Share this answer
 
Comments
LGSon2 4-Nov-13 3:06am    
Thanks for the link to expresso
OriginalGriff 4-Nov-13 3:13am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900