PHP program to demonstrate the quantifiers in pattern to search a string using a regular expression
belongs to collection: PHP Regular Expressions Programs
All Answers
total answers (1)
belongs to collection: PHP Regular Expressions Programs
total answers (1)
Program/Source Code:
The source code to demonstrate the quantifiers in pattern to search a string using regular expression is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a string variable $str, which is initialized with "There are five bananas in the bucket".
In the above code, we used quantifiers in pattern to search a string "banana" by looking for "ba" followed by two instances of "na".
In the above code, we checked the return value of the preg_match() function and then print the appropriate message on the webpage.
need an explanation for this answer? contact us directly to get an explanation for this answer