Is it possible to do multiple regex in one operation?

A

Ahmad Azizan

Hello,

I'm trying to grep some of the content from a file which contains
character ; or { or } or "while" or "function"

in shell, it similar to;
cat file.txt | grep -e ";" -e "{" -e "}" -e "while" -e "function

I've tried to use operation like below;
output.each {|f| puts f if f =~ /[;{}]/}
however, I failed to add another 2 keyword which are "while" and
"function"

I was wonder if multiple regex can be evaluate in one operation like
/[;{}]/,/while/,/function/ or
/[;{}]/ || /while/ || /function/
or any other forms

Thanks in advance

Ahmad Azizan,
 
R

Rajinder Yadav

Hello,

I'm trying to grep some of the content from a file which contains
character ; or { or } or "while" or "function"

This should work

/[;{}]|while|function/

use '|' or operator to separate 'while' and 'function' and place ; { }
inside the set clause [ ] for single match, make sense?
Thanks in advance

Ahmad Azizan,



--
Kind Regards,
Rajinder Yadav

http://DevMentor.org

Do Good! - Share Freely, Enrich and Empower people to Transform their lives.
 
A

Ahmad Azizan

Yes, both ways did working for me, thanks for the inputs. At first I
can't imaging regex does have 'and' or 'or' condition in it. But now I
believe

Really appreciate that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top