sv icon indicating copy to clipboard operation
sv copied to clipboard

Is there a better way to find a valid semantic version string in the text?

Open waruqi opened this issue 5 years ago • 0 comments

Currently I use lua pattern matching to find valid semantic versions, but I don't feel very reliable.

 function semver.match(str, pos, pattern) 
     local patterns = pattern or {"%d+[.]%d+[-+.%w]*", "%d+[.]%d+[.]%d+", "%d+[.]%d+"} 
     for _, pattern in ipairs(table.wrap(patterns)) do 
         local version_str = str:match(pattern, pos) 
         if version_str then 
             local info = semver.parse(version_str) 
             if info then 
                 local instance = table.inherit(_instance) 
                 instance._INFO = info 
                 return instance 
             end 
         end 

Would it be better to provide a semver.match interface in the sv library for fast matching?

see https://github.com/xmake-io/xmake/issues/677

waruqi avatar Feb 06 '20 06:02 waruqi