【问题标题】:PHP RegEx pattern for repeating within the string [duplicate]用于在字符串中重复的 PHP RegEx 模式[重复]
【发布时间】:2017-05-12 13:16:25
【问题描述】:

我正在尝试为这个字符串制作正则表达式:

This is some string <select> this is another string <select var1> another string which can contain special characters <select var2> another variable string <select var1,var2>

我需要选择所有不在选择标签中的字符串。

Select all string not within <select> tag

谁能帮忙?使用 PHP preg_match

【问题讨论】:

  • 你应该知道如何ask a good question
  • 你试过什么?你遇到了什么错误?
  • @Mohammad:是的,我在搜索了 3 个小时后发布了这个问题。
  • @Carlos :我试过 (.*)/(.*) ,它在 select 标签的单个实例上工作正常,但在多个实例上它没有返回任何东西。感谢您的帮助。

标签: php regex self repeat


【解决方案1】:

通过使用preg_split:

$str = 'This is some string <select> this is another string <select var1> another string which can contain special characters <select var2> another variable string <select var1,var2>';

$arr = preg_split('/\<.*?\>/',$str);
print_r($arr);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    相关资源
    最近更新 更多