Skip to content

Capture word after first dot and before second dot

i have some strings like: 

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


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

how can i do that? Thank you


You may use


See the regex demo and the regex graph:

enter image description here


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

JS demo:

var strs = [ '', 'test.router.hp.upload', '']
var rx = /^[^.]*.router./;
for (var i=0; i<strs.length; i++) {
  console.log(strs[i], '=>', rx.test(strs[i]))