How would I detect if a string contained for instance my first name but not my last name using only a regular expression?
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.
The easiest way to use regular expressions for this is to use simple regexes and logical connectives. Since you only want simple matches and since you didn’t list a language, here is a basic implementation in Perl:
As expected, the output is: