9

I am looking for the regex to stet if a string starts with another string. This has to be RegEx and it has to be PHP regex.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Slappy
  • 4,042
  • 2
  • 29
  • 41

1 Answers1

18
$result = preg_match("#^startText(.*)$#i", $string);
if($result == 0)
{
    echo "No match";
}
else
{
    echo "Match found.";
}

PHP.net Regular Expressions

preg_match returns either 0 for no matches found, or 1, because preg_match stops at the first match. If you want to count all matches, use preg_match_all.

Check the PHP website if you have more trouble.

Connor Deckers
  • 2,447
  • 4
  • 26
  • 45