For example
Season // matches
Season/Winter // wont match
Season/Spring // wont match
For example
Season // matches
Season/Winter // wont match
Season/Spring // wont match
I really doubt you'd need a regular expression for that in any language, anyway:
^[^/]*$
You can usually use string search methods such as JavaScript's indexOf
string method or PHP's strpos
function to try to find /
, most languages offer native string methods which are much faster and a better solution than regex, even more for something so simple.
Edit: For mongodb as OP's case, regex seems to be the most suitable solution though. I believe it should be more optimized than iterating through all records with another language's string function.
You're looking for a character class. These are the [
and ]
characters. inside, you specify the characters you are looking for. You can also add the ^
character, to indicate a negated character class, where it contains anything BUT the one you've specified. So, your regex is:
^[^/]*$
However, most string libraries have tools to look for a particular character. For example, in C#, you can do:
if (! String.Contains("/")) { /* your logic here */ }