匹配多行,这些行不在“< p>”开头不使用“ m&quot”修饰符(Golang味)
我试图匹配多个不以HTML < p>
标记的方式匹配,仅使用g
修饰符带有Regex的Golang风味。
以下是一个例子:
Lorem ipsum
<p><span class="slugline">INNEN. Wohnung, Erdgeschoss – Tag</span></p><br>
Dolor sit amet
1234
<p><span class="slugline">INNEN. Wieslers Wohnung, Fahrstuhl – Tag</span></p><br>
Et respice finem
<p><span class="slugline">AUSSEN. Wohnung - Nacht</span></p><br>
<p><span class="slugline">INNEN. Wohnung, Erdgeschoss – Tag</span></p><br>
<p><span class="charleft">Maik</span><span class="dialogleft">(leise) Hallo.</span></p>
Quod erat demonstrandum
正则应匹配以:
- lorem ipsum dolor
- sit amet
- 1234
- et Respice Finem
- Quod erat excliveandum,
使用Golang味的mg
修饰符很容易: ^([^&lt; \ n \ r] |&lt;([^p] | $))。
,
但是我正在寻找一个正则表达式,该表达式在没有m
修饰符的情况下工作。我不能仅适用于g
修饰符。
I'm trying to match multiple lines that do not begin with a HTML <p>
tag, using just the g
modifier with the Golang flavor of RegEx.
Here's an example:
Lorem ipsum
<p><span class="slugline">INNEN. Wohnung, Erdgeschoss – Tag</span></p><br>
Dolor sit amet
1234
<p><span class="slugline">INNEN. Wieslers Wohnung, Fahrstuhl – Tag</span></p><br>
Et respice finem
<p><span class="slugline">AUSSEN. Wohnung - Nacht</span></p><br>
<p><span class="slugline">INNEN. Wohnung, Erdgeschoss – Tag</span></p><br>
<p><span class="charleft">Maik</span><span class="dialogleft">(leise) Hallo.</span></p>
Quod erat demonstrandum
The regex should match the lines and paragraphs that begin with:
- Lorem ipsum
- Dolor sit amet
- 1234
- Et respice finem
- Quod erat demonstrandum
It's easy with the mg
modifiers of the Golang flavor: ^([^<\n\r]|<([^p]|$)).*
But I'm looking for a regular expression that works without the m
modifier. I can't make it work with just the g
modifier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其匹配要保留的内容,您可以匹配自己不需要的东西,并将其用作模式与 split 字符串。
如果您的文本位于变量
s
中,则可以继续这样做:然后将输出:
Instead of matching what you want to keep, you could match what you don't want, and use that as pattern to split the string.
If your text sits in variable
s
, you could continue like this:This will then output: