Regex get text between parentheses and keywords -


i have text pattern this;

(((a) or (b) or (c)) , ((d) or (e)) , ((!f) or (!g))) 

and want this;

((a) or (b) or (c)) ((d) or (e)) ((!f) or (!g)) 

after want seperate them this;

a,b,c d,e !f,!g 

any awesome :)

edit 1: sorry missing parts; using language c# , got;

(\([^\(\)]+\))|([^\(\)]+) 

with got;

(a) or (b) or (c) , (d) or (e) , (!f) or (!g) 

thanks already!

taking this previous regex , modifying code little...

string msg= "(((a) or (b) or (c)) , ((d) or (e)) , ((!f) or (!g)))"; var charsetoccurences = new regex(@"\(((?:[^()]|(?<o>\()|(?<-o>\)))+(?(o)(?!)))\)"); var charsetmatches = charsetoccurences.matches(msg); foreach (match mainmatch in charsetmatches) {     var sets = charsetoccurences.matches(mainmatch.groups[1].value);     foreach (match match in sets)     {         console.writeline(match.groups[0].value);     } } 

the first regex being used contents of outermost paren.

the same regex used individual sets within 'larger' content. output:

((a) or (b) or (c)) ((d) or (e)) ((!f) or (!g)) 

ideone demo

if want remove outer parens, change innermost line:

console.writeline(match.groups[0].value); 

to

console.writeline(match.groups[1].value); 

to get:

(a) or (b) or (c) (d) or (e) (!f) or (!g) 

i trust can take here.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -