regex - Splitting around an outer character in Perl. Minimal assumptions within group -


i having hard time adapting answer in this thread following problem:

i split following string:

my $string = "foo{age}, bar{height}. something_else. baz{weight,so='yes',brothers=john.smith}.test{some}" 

around outer dots. result should array holding

("foo{age}, bar{height}",   "foo{weight,parents='yes',brothers=john.smith}",   "test{some}") 

i avoid making assumptions what's inside groups inside {}.

how can in perl?

i tried adapting following:

print join(",",split(/,\s*(?=\w+{[a-z,]+})/g, $string)); 

by replacing what's inside character class [] without success.

update:

the characters not allowed within {} group { or }

since not dealing nested braces, periods want not "immediately" followed closing }. "immediately" means, without opening { in between:

split(/[.]\s*(?![^{]*[}])/g, $string) 

alternatively, match parts you're interested in:

(?:[^.{}]|[{][^{}]*[}])+ 

which can "unrolled" to:

[^.{}]*(?:[{][^{}]*[}][^.{}]*)* 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -