Can anyone please explain this /Won \d{1,2} Oscars?/ portion of below code for me. I can’t stuck at this code.
$match: {
awards: /Won \d{1,2} Oscars?/
}
Can anyone please explain this /Won \d{1,2} Oscars?/ portion of below code for me. I can’t stuck at this code.
$match: {
awards: /Won \d{1,2} Oscars?/
}
@byezid_71920 Regex is a pretty broad subject. I don’t know if MongoDB supports the full Perl Regex but the doc from @steevej-1495 should get you started. You’ll need to supplement your knowledge with external sources of information if you want to delve deep.
I’ll start you off with your example:
//
- you use these two backslashes to enter the Regex expression instead of quotes.
Won
- is just a word. Note that there’s a space after this word and it will also match that space.
\d{1,2}
- 1 or 2 numbers. The \d is for numbers 0 to 9 and the numbers in curly braces are the boundaries. There’s also a space after this.
Oscars?
- Oscar or Oscars. The question mark makes the preceding character “s” to be optional.
Therefore it will match the following few examples:
Won 1 Oscar
Won 1 Oscars
Won 20 Oscar
Won 20 Oscars
Won 07 Oscar
Won 09 Oscars
… Etc