gpt4 book ai didi

PHP REGEX - 在换行符处按 preg_split 排列的文本

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:38 25 4
gpt4 key购买 nike

已编辑:

需要拆分数组方面的帮助

数组示例:

 array (

[0] =>
:some normal text
:some long text here, and so on... sometimes
i'm breaking down and...
:some normal text
:some normal text
)

好的,现在通过使用

preg_split( '#\n(?!s)#' ,  $text );

我明白了

[0] => Array
(
[0] => some normal text
[1] => some long text here, and so on... sometimes
[2] => some normal text
[3] => some normal text
)

我想得到这个:

[0] => Array
(
[0] => some normal text
[1] => some long text here, and so on... sometimes i'm breaking down and...
[2] => some normal text
[3] => some normal text
)

什么 Regex 可以得到整行并在换行符处拆分!?

最佳答案

“换行符”定义不明确。 Windows 仅使用 CR+LF (\r\n)、Linux LF (\n)、OSX CR (\r)。

在preg_*正则异常中有一个鲜为人知的特殊字符\R匹配这三个:

preg_match('/^\R$/', "\r\n"); // 1

关于PHP REGEX - 在换行符处按 preg_split 排列的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2716324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com