【问题标题】:How to write a specific regular expression? [duplicate]如何编写特定的正则表达式? [复制]
【发布时间】:2016-11-15 21:57:21
【问题描述】:

我有以下文字:

"text tutorial" tutorial tipps tricks diy fashion "fashion style"

不,我想要一个将上面的文本拆分为单个关键字的正则表达式。引号中的所有关键字都应作为单个关键字进行罚款。

正则表达式的输出应该是这样的:

  1. 文字教程
  2. 教程
  3. 提示
  4. 技巧
  5. 自制
  6. 时尚
  7. 时尚风格

谢谢。

【问题讨论】:

标签: php regex


【解决方案1】:

使用str_getcsv(),试试:

str_getcsv($text, ' ')

str_getcsv() 的输出;

Array
(
    [0] => text tutorial
    [1] => tutorial
    [2] => tipps
    [3] => tricks
    [4] => diy
    [5] => fashion
    [6] => fashion style
)

【讨论】:

  • 您的正则表达式代码未返回预期结果。 str_getcsv() 是这里最好的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 2010-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多