regex - Regular expression for splitting a string and add it to an Array -


i have string in following format:

[0:2]={1.1,1,5.1.2} 

my requirement here split values inside curly braces after = operator, , store them in string array. had tried split part using substring() , indexof() methods, , worked. needed cleaner , elegant way achieve via regular expressions.

does having clues achieve requirement?

here regex solution:

dim input string = "[0:2]={1.1,1,5.1.2}"  dim match = regex.match(input, "\[\d:\d\]={(?:([^,]+),)*([^,]+)}")  dim results = match.groups(1).captures.cast(of capture).select(function(c) c.value).concat(match.groups(2).captures.cast(of capture).select(function(c) c.value)).toarray() 

don't think more readable standard split:

dim startindex = input.indexof("{"c) + 1 dim length = input.length - startindex - 1 dim results = input.substring(startindex, length).split(",") 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -