<script type="text/javascript">
if(ytu==undefined){var ytu={q:'//img10-server.com/image/7777-88-78678678676876/robotunique-testfile.png',po:'6567567567',
我对bash / sed和其他linux脚本有点新意,我试图从上面的源代码中grep文件名“robotunique-testfile.png”,可靠而不会造成潜在的误报。
我在想也许greping "/\.png\'\,po\:/"
在这个例子中足够独特。如何将此grep转换为选择文件名"robotunique-testfile.png"
答案 0 :(得分:0)
您可以使用以下正则表达式(https://regex101.com/r/4LPNS0/1):
# Take each frame
_, frame = cap.read(0)
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([80,30,30])
upper_blue = np.array([130,150,210])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# applica filtri morfologici
mask = cv2.erode(mask, spotFilter)
mask = cv2.dilate(mask, maskMorph)
# ^Now the mask is a black and white image.
# ^Get height of the black region in this image
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
说明:
(?<=\/)[^'\/]+(?=')
在grep中使用此正则表达式:
(?<=\/) Look behind for a slash
[^'\/]+ Match anything but quote or slash
(?=') Look ahead for a quote
您已经提到正则表达式应该可靠地执行并且不会导致潜在的误报。&#34;在这种情况下,您可以将grep -Po "(?<=\/)[^'\/]+(?=')" InputFile.txt
替换为更通用的类:[^'\/]