Efficient way in using lookarounds for regex split -


in c#, trying split following string

(hello)(world)(hello)(world) 

into array of following format

arr[0] = ( arr[1] = hello arr[2] = ) arr[3] = ( arr[4] = world arr[5] = ) arr[6] = ( arr[7] = hello arr[8] = ) arr[9] = ( arr[10] = world arr[11] = ) 

i using following regex expression perform split , appears slow

regex.split(value1, @"(?<=\))|(?=\))|(?=\()|(?<=\()") 

i no expert regex have gut feeling there regex expression provides same functionality in efficiently manner.

wondering if there better ways (more efficient regex expressions) implement same split in c#?

you try match these tokens instead:

regex.matches(value1, @"[()]|[^()]+") 

here pattern [()]|[^()]+ matches either single ( or ), or sequence of characters except ( , ).


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -