简体   繁体   中英

How python regex to find or search only the exact world/text

I have process "httpd" in the below example which is running as full path as " /usr/sbin/httpd " , I'm using a python script to catch these process but the reason when i search for " httpd " it takes " httpd " even if it has anything attached pre or suffixed example: " KKhttpdS_PS " or " which_httpd_running " which i don't want.

Saying that, i would like to search unique string " httpd " or if it has " / or /usr/bin/ or /usr/sbin/ or /usr/local/bin/ " like in below that's okay, but it shouldn't have anything after " httpd " ... that's the requirement...

10971 apache   /usr/sbin/httpd              1-06:16:59
10972 apache   /usr/sbin/httpd              1-06:16:59

maybe this is what you need.

r'httpd\\s+'

And \\s+ means one or more spaces.

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