Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone help me out with some regex?

Tags:

arrays

c#

regex

I'm trying to get an int[] from the following string. I was initially doing a Regex().Split() but as you can see there isn't a definite way to split this string. I could split on [a-z] but then I have to remove the commas afterwards. It's late and I can't think of a nice way to do this.

"21,false,false,25,false,false,27,false,false,false,false,false,false,false,false"

Any suggestions?

like image 306
Joey Green Avatar asked Nov 29 '25 23:11

Joey Green


1 Answers

Split on the following:

[^\d]+

You may get an empty element at the beginning if your string doesn't begin with a number and/or an empty element at the end if your string doesn't end with a number. If this happens you can trim those elements. Better yet, if Regex().Split() supports some kind of flag to not return empty strings, use that.

like image 134
Asaph Avatar answered Dec 02 '25 12:12

Asaph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!