I have this regular expression that extracts guid and couple of other attributes like name, type and version. Please review the regex for any optimizations and improvements.
Strings are always in the pattern of
/publication/guid/type/name;version=1234
regex
(([a-f0-9]+\-)+[a-f0-9]+)\/(.*?)\/(.*?);version=(\d*)
Test records
Extract bold pieces from string.
/publication/d40a4e4c-d6a3-45ae-98b3-924b31d8712a/collection/content1;version=1520623346833
Expected output:
- d40a4e4c-d6a3-45ae-98b3-924b31d8712a
- collection
- content1
- 1520623346833
/publication/d40a4e4c-d6a3-45ae-98b3-924b31d8712a/article/testContent;version=1520623346891
Expected output
- d40a4e4c-d6a3-45ae-98b3-924b31d8712a
- article
- testContent
- 1520623346891
Code
Language is F#, but the regex works in C# too. Furthermore, I would like to use the same regex in Node.js, so I would like the regex to be language agnostic.
let matchEntity (m: Match) =
{ id= m.Groups.[1].Value; eType = m.Groups.[3].Value; name= m.Groups.[4].Value; version = m.Groups.[5].Value}
let regex = new Regex("(([a-f0-9]+\-)+[a-f0-9]+)\/(.*?)\/(.*?);version=(\d*)")
matchEntity regex.Match "/publication/d40a4e4c-d6a3-45ae-98b3-924b31d8712a/collection/content1;version=1520623346833"