Home > database >  egrep matching both \[ and \] with [ ... ]
egrep matching both \[ and \] with [ ... ]

Time:05-20

I'm trying to get this regex to work egrep '[a-zA-Z\]\[]*' <<< '{[dict]}'

Both of these work

% egrep '[a-zA-Z\]]*' <<< '{[dict]}' 
{[dict]}

% egrep '[a-zA-Z\[]*' <<< '{[dict]}'
{[dict]}

but for some reason having both [ and ] together produces no matches


Also if I add -o I get

% egrep -o '[a-zA-Z\]]*' <<< '{[dict]}'
d
i
c
t]

CodePudding user response:

From enter image description here

What you're trying, modified to conform to that rule, works:

$ egrep '[]a-zA-Z\[]*' <<< '{[dict]}'  
{[dict]}
  • Related