mmmm
mmmm

Reputation: 3938

Regex in MongoDB - match until dot

I have string ( which may contains dots ) and I want to find in my collection other records which starts like given string, have dot right after this string and match it until another dot appears.

So for example : string = "Test.Gummy" and I want to look for "Test.Gummy.Yummy", "Test.Gummy.Crummy", etc.

I was trying with:

/{string}.*[^.]/ 

/{string}(.*?)\./ 

/{string}\.*[^.]/ 

/{string}\.(.*?)\./ 

but that doesn't work..

Upvotes: 0

Views: 3054

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Your regex would be,

/{string}\.[^\.]*/ 

Explanation:

  • \. Matches a literal dot.
  • [^\.]* Matches any characters not of dot zero or more times.

Upvotes: 1

Related Questions