Home > database >  Match words which are not inside parenthesis
Match words which are not inside parenthesis

Time:04-02

this is the sample of my long text(my original text is about 20000 line)


(fault)its over

(favor)im coming

(favour)sure

(favours)nothing but this

(fear)all of them

(fears)thanks

(feature)main study

. . . I want to match these words: 'its over', 'im coming', 'sure', 'nothing but this', 'all of them', 'thanks', 'main study'

i mean i want to match every words that'ss not in parenthesis

CodePudding user response:

The following regex will work as long as you don't have any nested parentheses:

(?<=^|\))[^(\r\n] 

Test it here.

Explanation: Match the rest of the line after the closing parenthesis, or if the line doesn't contain any parentheses, just match the whole line.

PS: This is PCRE syntax. You'll need to use a PCRE compatible regex library. If you are using a shell script, grep -P works.

  • Related