I have a regex from Golang (nameComponentRegexp). How can I convert it to JavaScript style regex?
The main blocking problem for me:
- How can I do
optional
andrepeated
in JavaScript correctly - I tried copy from
match(`(?:[._]|__|[-]*)`)
but it cannot match single period or single underscore. I tried it from online regex tester.
The description from Golang:
nameComponentRegexp restricts registry path component names to start with at least one letter or number, with following parts able to be separated by one period, one or two underscore and multiple dashes.
alphaNumericRegexp = match(`[a-z0-9]+`)
separatorRegexp = match(`(?:[._]|__|[-]*)`)
nameComponentRegexp = expression(
alphaNumericRegexp,
optional(repeated(separatorRegexp, alphaNumericRegexp)))
Some valid example:
- a.a
- a_a
- a__a
- a-a
- a--a
- a---a