简体   繁体   English

如何在PHP中的字母后匹配2个未知字母

[英]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 . 我希望S02E06不在完整的字符串中。 and if possible split the string there. 并尽可能在该位置拆分字符串。 Please note that the values after S and E in that keep changing so its not constant . 请注意,S和E之后的值会不断变化,因此它不是恒定的。 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. PHP具有preg_match() ,您将使用它。

The regex to match would be something like S\\d+E\\d+ . 要匹配的正则表达式将类似于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. 您需要将所有这些想法组合在一起才能得出答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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