mega-crazy
mega-crazy

Reputation: 858

How to match 2 unknown letters after a letter in php

i am trying to get this

string = 'Boss S02E06        more string'

i want S02E06 out of the complete string . and if possible split the string there. Please note that the values after S and E in that keep changing so its not constant . But im not expert when it comes to it.But i guess its time to start learning.

Thanks guys

Upvotes: 1

Views: 73

Answers (2)

mgraph
mgraph

Reputation: 15338

try this:

$string = "Boss S02E06        more string";
preg_match(`.*(S\d+E\d+).*`,$string,$match);
echo $match[0];// it will echo S02E06

Upvotes: 1

alex
alex

Reputation: 490413

You would use a Regular Expression. You can learn them here.

PHP has preg_match(), which is what you would use.

The regex to match would be something like S\d+E\d+. If you want the values, use a capturing group.

It's up to you to put all these ideas together to arrive at an answer.

Upvotes: 0

Related Questions