Reputation: 455
I'm a little confused about the usage of regular expression in all the entry string.
I need to understand if a given string contain any number or symbols, or viceversa don't contain any letters:
good | no good |
---|---|
! | |
- 1 - | |
=> | |
foo | |
foo bar | |
{ | |
I have 3 bananas | |
123 456 |
So I need something like that /[^A-Za-z]/
but in the strign I have 3 bananas the preg_math_full
is fired, how can I use the regex pattern in all the string??
Upvotes: 0
Views: 45
Reputation: 15247
If you want to exclude letters, you can simply search for [a-z]
and reverse the result, such as :
$testArray = [
"!",
"- 1 -",
"=>",
"foo",
"foo bar",
"{",
"I have 3 bananas",
"123 456"
];
foreach ($testArray as $element)
{
echo "$element is ";
// v--- check this
if (!preg_match("#[a-z]#i", $element))
{
echo "good" . PHP_EOL;
}
else
{
echo "not good" . PHP_EOL;
}
}
This will output :
! is good
- 1 - is good
=> is good
foo is not good
foo bar is not good
{ is good
I have 3 bananas is not good
123 456 is good
Upvotes: 1