I’m trying to write a PHP script that finds all words in a list or a paragraph that have more than one capital letter – or a mix of at least 1 letter and 1 number. I Can find one capital letter, but 2 capital letters in a word is an issue.
Thank you
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.
I hope I got your question right. These regular expressions matches all the words that have at least 2 capital letters in them or have at least 1 letter + 1 number (e.g. HEllo, HellO, Hello1, hello2, etc). It uses the space as separator so it might fail with punctuation, including commas, points and other things in the matches.
(Explanation: it matches every word that is preceded and followed by a space (but don’t include them in the match), which has something that’s not a space repeated 0, 1 or more times, a capital letter, again a non-space repeated 0, 1 or more times, again a capital letter and again something that’s a non-space, or the same but in place of the capital letters you have a letter and a number, or a number and a letter)
In order to use this you need
PHP > 5.1.0. The advantage is that it matches all the unicode characters that are considered letters or numbers, not just ASCII. If you don’t need this, or have a minor version of PHP, you can use the ASCII version: