Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 13 Use regular expressions and preg_match to answer this question! Writ

ID: 3842634 • Letter: Q

Question

QUESTION 13

Use regular expressions and preg_match to answer this question!

Write the PHP code that will print "YES!" if the variable $wordString begins with a lowercase letter, ends with a lower case letter and contains (anywhere in the string!) three digits in a row. Otherwise the code prints "NO!"

So art453Xt would print YES!, a561z would print YES!, r45az590t would print YES! 6tu789x would print NO! because it does not start with a lower case letter, a45dhj78sk8z would print "NO!" because it does not have 3 digits in a row.

Explanation / Answer

$regex = "/^[a-z][a-z0-9]|[0-9]{3}[a-zA-Z0-9][a-z]$/";


$String = "6tu789x ";


if(preg_match($regex, $String))
{
echo "YES!";
}
else
{
echo "NO!";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote