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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -