简体   繁体   中英

Writing Regex for multiple patterns

I am extremely new to regex and have to implement in for a final project in my grad school curricula. I have to read last login info on unix which can contain various record types such as

Here is an example of one of the lines that I have to match. I am trying to figure out what is the best way of matching each of the individual items in the output. There is a username, terminal, start date time, start date end time, duration and host. I am looking for tips on the most efficient way to match multiple lines such as the one below.

fraziered pts/50 Thu Oct 27 09:02:38 2016 - Thu Oct 27 10:05:10 2016 (01:02) rnh49119.etsu.edu

Well, I have tried going item by item in the line of text. For example creating a regex for username then for terminal etc. I plan on piecing it all together at the end using python when I read the file line by line. Is it best practice to do it this way or would a better way be writing one big regex?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM