【问题标题】:Finding a string that matches till http is found [duplicate]查找匹配的字符串,直到找到 http [重复]
【发布时间】:2017-04-08 10:51:51
【问题描述】:
# Example Agreement

`Purpose` You give a short description.

`Party 1 Name` Seller

`Party 2 Name` Buyer

Speak This is the place where {{document advantage}} goes and this is where {{remove fourth}} goes.  

Then there is this: {{remove last two}}  Then we will have {{standard time}}.

Also, {{remove optional widgets}}.  Then there is also {{standard list}}.

https://github.com

我需要从 `Speak 中获取字符串,直到找到 \n 并找到 http 即。我需要

说这是 {{document 优势}} 去的地方,也是 {{remove Fourth}} 去的地方。

然后是这样的:{{remove last two}} 然后我们将有 {{standard time}}。

另外,{{删除可选小部件}}。然后还有{{standard list}}。

结果。

这是我尝试过的。但是得到以 h 结尾的字符串

[Ss]峰值(.+)([\s\S]+?)(\n[http]|$)

【问题讨论】:

  • 请分享你的努力。 SO 不是免费获取代码网站。
  • 练习正则表达式,尤其是看看积极的前瞻来解决你的问题。
  • @Rajesh 添加了我尝试过的正则表达式。
  • @Eddi 您能否分享正则表达式,因为我在创建这些正则表达式时遇到问题。使用了积极的前瞻,但无法在此处实施

标签: javascript regex


【解决方案1】:

针对您的测试字符串测试了这个 RegEx:

([Ss]peak(.|\r|\n)*?(?=http))

(?=http) 部分是肯定的前瞻,它断言在你的字符串末尾http 跟在后面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 2013-05-21
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多