I have the following regex so far:
printf "this is (test.com)\n" | grep -Po '(?<=\().*(?=\))'
The above regex will print the desired output, which is test.com
As far as I am adding new parenthesis to my code
printf "this is (test.com) and (alex)\n" | grep -Po '(?<=\().*(?=\))'
, it displays something like:
test.com) and (alex
I would like my regex to print anything between brackets (no matter how many there are). More, I would like to add a condition to print just words between brackets with a specific length.
Eg: (aaa) test1 (bbb) test test (ccc) test (example) (ddd)
I just want printed out the words between brackets that have length 3. So the output should be:
aaa bbb ccc ddd
[^)]instead.or if you already use -P (pcre regex) to prohibit regex be greedy you should add?after*:grep -Po '(?<=\().*?(?=\))'quantificatorthoroughly. Three characters can be choised like...(any 3 symbols) or, for example\w{3}(any 3 alphanumeric symbols)