Techiio-author
Started by James CharlesSep 4, 2021

Open
Why This RegExp Pattern Hits Two Matches Only

0 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWES SHARE

Here is my code

let text = 'test.users.mail.com'
let pattern = /(\w+\.)+\w+/i;
let matches = pattern.exec(text)

console.log(matches.index)
console.log("0", matches[0])
console.log("1", matches[1])
console.log("2", matches[2])

There are only two matches found, they are: "test.users.mail.com" and "mail.".

So why sequence like users. doesn't match? I don't understand.

0 Replies

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance