Click here to Skip to main content
15,886,781 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to use preg_match() to compare it with a string starting with a particular string and ending with another particular string eg .. "Hello[some other text]Bye" ... It should be something like preg_match("/^Hello Bye$/","Hello[some other text]Bye")) . Can any one help?

What I have tried:

i tried to insert . but it worked only for one character in between Hello and Bye
Posted
Updated 4-Jul-17 2:45am

1 solution

See: PHP: PCRE Patterns - Manual[^]

In particular: PHP: Repetition - Manual[^]
PHP
// If the other text is optional:
preg_match("/^Hello.*Bye$/","Hello[some other text]Bye"))

// If the other text is required:
preg_match("/^Hello.+Bye$/","Hello[some other text]Bye"))

// If the other text must be at least five characters:
preg_match("/^Hello.{5,}Bye$/","Hello[some other text]Bye"))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900