5

I am looking for a pattern regular expression that is matching of first 3 character of string.
For example , I have two number like this: 011569875 and 041568956
If I found first 3 character 011 ,then I will print 011569875

4
  • 2
    You don't need a regular expression to test that, why not simply use substr()? Commented Oct 7, 2015 at 18:05
  • How can I use substr() for this purpose? Commented Oct 7, 2015 at 18:11
  • 1
    if (Substr($MyString,0,3)=="011") { echo $MyString;} Commented Oct 7, 2015 at 18:14
  • 1
    echo substr($number,0,3) == '011' ? $number : ''; assuming your values are really strings Commented Oct 7, 2015 at 18:15

1 Answer 1

2

As suggested by @Mark, you can use substr as follows:

$string = substr($longstring,0,3);
if($string == '011'){
   echo $longstring;
}

Hope this helps. Cheers

Sign up to request clarification or add additional context in comments.

1 Comment

Not a regex solution though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.