Can I capture a label not found in the test string using regex? -


assuming have strings of following type:

session opened (uid=0) session opened scotty 

is possible write regex either capture text "root" if (uid=0) found in string, otherwise capture normal user name (i.e. scotty)?

regex not allow capture is missing input string. if know structure of input text, can have regex pattern return required part. here example works .net-based regex flavor:

(?s)(?<=\(uid=0\).*opened )\w+  matches found: [0][0] = scotty 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -