Skip to content
Advertisement

Capture word after first dot and before second dot

i have some strings like:

JavaScript

I’m trying to write a regex that makes the first two string pass, but not the third one. The rule is that if the string contains the word “router” after the first dot and before the second dot it’s ok.

i tried with

JavaScript

but it match every .router. in my string, so also the third one pass.

how can i do that? Thank you

Advertisement

Answer

You may use

JavaScript

See the regex demo and the regex graph:

enter image description here

Details

  • ^ – start of string
  • [^.]* – 0+ chars other than .
  • .router. – a .router. substring.

JS demo:

JavaScript
Advertisement