I need extract data from a string. Heres an example:
Mozilla/5.0 (Macintosh; U; PPC Mac OS
X; tr-tr) AppleWebKit/418 (KHTML, like
Gecko) Safari/417.9.3
I want to get what’s after the “Safari/” (417.9.3) but:
- The “Safari” string can be in any character case and can be anywhaere in the string.
- The version is separated from “Safari” by “/”, ” /”, “/ “, ” / ” or any whitespace.
- The version string end by any whitespace, “)”, “(“, “;”, or the end of the string.
Anyone can help me build this up?
Thanks!
The
iat the end means “case insensitive”, which answers criteria one.(\s+|\s*/\s*)?matches either at least one whitespace character or a slash preceded and followed by an arbitrary number of whitespace characters (from zero to infinity and beyond), which addresses criteria two.[^)(;]+will match as many characters as possible that are not inside the set, which addresses criteria three.