I have a string, it can either be “word” or “word (something)”. How can I only match “word”, but not “word (something)”?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depending on the regex flavor, you can probably use a negative lookahead. Like this:
Just checks to make sure there isn’t a space and the word something after the matched word.
Oh, and if you have JUST the word “word” in the string, you could do:
which makes sure that
wordis the start(^)and the end($)of the string.But if you had JUST the word “word” in the string, you could have just done