I need a regex to recognize only two options, they are ‘F’ and ‘M’ chars. I am trying:
preg_replace('/([^FM]){1}/', '', $_GET['option'])
But if i type ‘MF’ it returns ‘MF’, but i am expecting ‘M’.
Can anybody help me?
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.
Start at the beginning of the string. Consume all non-
FMcharacters. Then match oneForMcharacter (if there is one). Match the rest of the input. Replace with the matched character. Note that you will end up with an empty string if there was noMorFat all.However, you should probably rethink how you get that data, since it seems to be a boolean value (but you take care of an arbitrary string that might contain the desired characters).
If you generate the value yourself (from some other website), you should be able to know that values that haven’t been tampered with are either
"M"or"F". So why not just go with: