简体   繁体   中英

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

try this:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM