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
Post a Comment