1

I want to search a set of specific string from a word using PHP regular expression. The pattern is like this

  1. The string is of 6 character length

  2. First 5 characters of this string are number 0-9

  3. Last 1 character is a A-Z or a-z alphabets

  4. there are more then one strings like this in a Word.

So eg. the word is

037165L_55084L_1959Z

Then the output of regular expression should return below 2 strings

37165L
55084L
1
  • sorry, its updated now. thanks for noticing. Commented Jun 13, 2015 at 5:47

3 Answers 3

2

You can use just use this regex in preg_match_all function:

\d{5}[a-zA-Z]

RegEx Demo

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

2 Comments

This doesn't meet #4 requirement ;)
It does meet that requirement due to my suggestion of preg_match_all function :)
0

Use this function

    $string="your_character"
    $string = str_replace('your_character',' ',$string);
echo  $string;

Eg..

$string="037165L_55084L_1959Z"
    $string = str_replace('_55084L_1959Z',' ',$string);
echo  $string;

Comments

0

This regex should work for you:

 /([0-9]{5}[A-Za-z]).*([0-9]{5}[A-Za-z])/

Comments

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.