lines lines - 12 days ago 6
Bash Question

grep exclude strings somthing with regular expression string

I had a test file:

base64_decode(xxx)
bas'.'e64'.'_decode(xxx)
ba'.'s'.'e64'.'_deco'.'de(xxx)
xxxxxxx
ttttttt
bbbbbb
vvvvvvv
b'.'a'.'s'.'e'.'64'.'_de'.'co'.'de(xxx)


I had the test command

grep -i -E -e "b[\'\.]*a[\'\.]*s[\'\.]*e[\'\.]*6[\'\.]*4[\'\.]*_[\'\.]*d[\'\.]*e[\'\.]*c[\'\.]*o[\'\.]*d[\'\.]*e[\'\.]*" test.txt


But,the result included the line

base64_decode(xxx)


I want remove this line:

base64_decode(xxx)


and must include this lines:

bas'.'e64'.'_decode(xxx)
ba'.'s'.'e64'.'_deco'.'de(xxx)
b'.'a'.'s'.'e'.'64'.'_de'.'co'.'de(xxx)


I think my regular expression string is wrong.

So help me please, thanks~~~

Answer

I don't know grep, so I'm not sure if this regex will work as it requires support for positive lookahead. But here it is:

^b(?=[ase64_dcod]*')[.']*a[.']*s[.']*e[.']*6[.']*4[.']*_[.']*d[.']*e[.']*c[.']*o[.']*d[.']*e[.']*.+$

Basically checks to see if there is a single quote somewhere after the initial 'b' before matching the rest of the string.

If supported, possessive modifiers (+) after the *'s might speed up searches.

https://regex101.com/r/UiCyCN/2