如何获得匹配,直到最后一个不是空格的字符

时间:2017-10-01 16:00:30

标签: regex

我有以下文字:

import cv2
import numpy as np 
import pickle


cam = cv2.VideoCapture(0);
faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml');

id = raw_input('Enter user Name')

sampleNo = 0;

while(True):

    ret,img = cam.read();
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = faceDetect.detectMultiScale(gray, 1.3, 5);
    for(x,y,w,h) in faces:
        sampleNo = sampleNo+1;
        cv2.imwrite("dataSet/"+str(id)+"_" +str(sampleNo)+ ".jpg", gray[y:y+h, x:x:w])
        cv2.rectangle(img,(x,y),(x+w, y+h), (0,0,0), 2)
        cv2.waitKey(100);
    cv2.imshow("Face", img);
    cv2.waitKey(1);
    if(sampleNo > 20):
        break;
cam.release()
cv2.destroyAllWindows()

*通知空格:
enter image description here

我想在每一行都得到匹配,直到最后一个不是空格的字符 这就是我想要的:

aa              
bb cc           
dd              
ee ff gg         

看起来像这样:
enter image description here

我试着遵循:
Match until the next (and not the last) space after a specific pattern

并使用:

aa
bb cc
dd
ee ff gg

但它没有帮助。

1 个答案:

答案 0 :(得分:1)

我找到了怎么做:

.*([^\s]+)

参考:
regular expression: match any word until first space