我想匹配包含单词" name"的任何字符串。和理查德" (按此顺序)前面没有单词" hello"。
正则表达式应匹配:
我的名字是理查德
姓理查德
等
但它不应该匹配:
你好,我的名字是理查德
#hello,我的名字是理查德
理查德姓名
等
我尝试了以下Regexps,但它们无法正常工作:
(^你好)。*名称*理查德
(?<你好!)名*理查德
。
(小于?= ^你好)。名*理查德
感谢您的帮助!
答案 0 :(得分:2)
使用单个正则表达式:
[root@offworld teamspeak]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:30033 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:10011 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 256 192.168.1.4:22 192.168.1.2:50066 ESTABLISHED
tcp 0 0 192.168.1.4:22 192.168.1.2:51516 ESTABLISHED
tcp 0 0 192.168.1.4:22 192.168.1.2:50058 ESTABLISHED
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::30033 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 :::10011 :::* LISTEN
tcp6 0 0 :::201 :::* LISTEN
播放
回应@Mateus评论:是的,此正则表达式匹配import turtle
Screen = turtle.Screen()
P1 = turtle.Turtle()
P2 = turtle.Turtle()
Screen.screensize(100, 100)
x1 = []
x2 = []
y1 = []
y2 = []
P1.penup()
P1.setheading(180)
P2.setheading(90)
P1.goto(100, 50)
P2.penup()
P2.goto(50, 0)
P2.pendown()
P1.pendown()
n = 0
Num = 0
XC = P2.position()[0]
YC = P2.position()[1]
x1.append(XC)
y1.append(YC)
while Num == 0:
XC = P2.position()[0]
YC = P2.position()[1]
x1[n] = XC
y1[n] = YC
if P1.heading() is 180:
XC = P2.position()[0]
YC = P2.position()[1]
x2[n] = XC
y2[n] = YC
P1.position()
XC1 = P1.position()[0]
YC1 = P1.position()[1]
for x in range(0, n):
for z in range(x1.index(x), x2.index(x)):
if abs(z-YC1)<10:
print("Found")
P2.forward(1)
P1.forward(0.5)
。您可以通过以下方式阻止匹配:
^((?<!hello).)*name.*Richard
同样在regex101上查看此内容。