Reputation: 3935
I want to search a set of specific string from a word using PHP regular expression. The pattern is like this
The string is of 6 character length
First 5 characters of this string are number 0-9
Last 1 character is a A-Z or a-z alphabets
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
Upvotes: 1
Views: 69
Reputation: 785246
You can use just use this regex in preg_match_all
function:
\d{5}[a-zA-Z]
Upvotes: 2
Reputation: 1655
This regex should work for you:
/([0-9]{5}[A-Za-z]).*([0-9]{5}[A-Za-z])/
Upvotes: 0
Reputation: 1671
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;
Upvotes: 0