【问题标题】:Modify a pattern to allow "+" or "-" to appear at the front of the phrase修改模式以允许“+”或“-”出现在短语的前面
【发布时间】:2012-11-11 15:22:39
【问题描述】:

我有一个工作模式

/[^\s"']+|"([^"]*)"|'([^']*)'|/ 

将由空格分隔的单个单词或短语(双引号或单引号)拆分为匹配数组。我想修改模式以允许“+”符号或“-”符号出现在单词/短语的开头,因此 preg_match_all 不会将 + 或 - 拆分为单独的匹配项,即:

guide -"test * of" +'guide'

我希望它分成以下匹配项

[0] => Array
    (
        [0] => guide
        [1] => -"test * of"
        [2] => +'guide'
    )

提前致谢。

【问题讨论】:

    标签: php preg-match preg-match-all


    【解决方案1】:

    尝试以下模式: /[+-]?([^\s"']+|"([^"]*)"|'([^']*)')/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      相关资源
      最近更新 更多