Regular Expression for "AND"?

Posted by Kevin on Server Fault See other posts from Server Fault or by Kevin
Published on 2012-03-25T15:29:48Z Indexed on 2012/03/25 17:32 UTC
Read the original article Hit count: 175

Filed under:

Let's say I gave you the following text:

allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> on
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off

What I want to do is create a regular expression that can parse text like this looking for two or more words on the same line. For example, if I was looking for a SELinux boolean that covered "ftp" AND "home" on the same line, I would currently do the following:

getsebool -a | grep -i ftp | grep -i home

However, I am looking for a regular expression that does the same thing. Specifically, find all of the words in any order on a line...

© Server Fault or respective owner

Related posts about regex