在分隔符的第三个实例上分割字符串

发布于 2024-08-25 22:41:35 字数 540 浏览 5 评论 0原文

我有一些这种格式的测试用例/字符串:

o201_01_01a_Testing_to_see_If_this_testcases_passes:without_data
o201_01_01b_Testing_to_see_If_this_testcases_passes:data
rx01_01_03d_Testing_the_reconfiguration/Retest:

实际上这个测试用例名称由实际名称和描述组成。

所以,我想像这样分割它们:

o201_01_01a   Testing_to_see_If_this_testcases_passes:without_data
o201_01_01b   Testing_to_see_If_this_testcases_passes:data
rx01_01_03d   Testing_the_reconfiguration/Retest:

我无法弄清楚在 php 中爆炸中执行此操作的确切方法

有人可以帮忙吗?

谢谢。

I have some testcases/strings in this format:

o201_01_01a_Testing_to_see_If_this_testcases_passes:without_data
o201_01_01b_Testing_to_see_If_this_testcases_passes:data
rx01_01_03d_Testing_the_reconfiguration/Retest:

Actually this testcase name consists of the actual name and the description.

So, I want to split them like this :

o201_01_01a   Testing_to_see_If_this_testcases_passes:without_data
o201_01_01b   Testing_to_see_If_this_testcases_passes:data
rx01_01_03d   Testing_the_reconfiguration/Retest:

I am unable to figure out the exact way to do this in explode in php

Can anyone help please?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青瓷清茶倾城歌 2024-09-01 22:41:35

如果第一部分始终具有相同的长度,为什么不使用 substr ,例如

$string = "o201_01_01a_Testing_to_see_If_this_testcases_passes:without_data";
$first_part = substr($string, 0, 11); // o201_01_01a
$second_part = substr($string, 12); // Testing_to_see_If_this_testcases_passes:without_data

If the first part has always the same length, why don't you use substr, e.g.

$string = "o201_01_01a_Testing_to_see_If_this_testcases_passes:without_data";
$first_part = substr($string, 0, 11); // o201_01_01a
$second_part = substr($string, 12); // Testing_to_see_If_this_testcases_passes:without_data
大姐,你呐 2024-09-01 22:41:35

$results = preg_split("/([a-z0-9]+_[0-9]+_[0-9]+[a-z])(.*)/", $input);

如果我的正则表达式正确的话,这应该会给你一系列结果。

http://www.php.net/manual/en/function。 preg-split.php


$results = preg_split("/([a-z0-9]+_[0-9]+_[0-9]+[a-z])(.*)/", $input);

That should give you an array of results, provided I got the regular expression correct.

http://www.php.net/manual/en/function.preg-split.php

感情废物 2024-09-01 22:41:35

查看该模式,看来您需要使用正则表达式。如果都是这样,您可以通过查找大写字符来截断开头。代码可能如下所示:

$matches = array()
preg_match('/^[^A-Z]*?/', $string, $matches);
$matches = substr($matches[0], 0, count($matches[0])-1);

将第一个小部分放入 $matches 中。正在制作第二部分...

Looking at the pattern, it appears that you need to use regular expressions. If this is how they all are, you can cut off the beginning by looking for an upper case character. The code might look like this:

$matches = array()
preg_match('/^[^A-Z]*?/', $string, $matches);
$matches = substr($matches[0], 0, count($matches[0])-1);

Would put the first little part into $matches. Working on second part...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文