Regular expression in BASH

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-03-12T01:01:10Z Indexed on 2010/03/12 1:07 UTC
Read the original article Hit count: 406

Filed under:
|
|

Hello everyone, I was hoping someone could answer my quick question as I am going nuts!

I have recently started learning regular expressions in my Java programming however am a little confused how to get certain features to work correctly directly in BASH. For example, the following code is not working as I think it should.

echo 2222 | grep '2\{2\}'

I am expecting it to return:

22

I have tried variations of it including:

echo 2222 | grep '2{2}'
echo 2222 | grep -P '2\{2\}'
echo 2222 | grep -E '2\{2\}'

However I am completely out of ideas. I'm sure this is a simple parameter / syntax fix and would love some help! P.S I've done tons of googling and every reference I find does not work in BASH; regex's can run on so many different platforms and engines =/

© Stack Overflow or respective owner

Related posts about regex

Related posts about bash