【问题标题】:PHP explode string using a regular expressionPHP使用正则表达式分解字符串
【发布时间】:2012-02-13 01:11:23
【问题描述】:

我有一个由单引号分隔的一系列句子组成的长字符串。

例子:

This\'s sentence number 1'This\'s sentence number 2'

请注意,该字符串有句子本身的单引号部分被转义。我需要使用单引号来分解字符串,而不是转义的单引号。

输出应该是:

Array{
      [0]=>This\'s sentence number 1
      [1]=>This\'s sentence number 2
}

基本上我需要分解 { ' } 上的字符串,而不是 { \' }。 提前致谢。

【问题讨论】:

  • ending with backslash\\'s uiae 呢?
  • @knitti 我无法控制提供的字符串。我只需要解析它。

标签: php regex parsing


【解决方案1】:

试试这个:

print_r(preg_split("/(?<!\\\)\'/", "This\'s sentence number 1'This\'s sentence number 2'"));

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多