Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression Commas and Columns

Tags:

.net

regex

I have an issue while parsing my Solr Queries that I pass on the querystring:

The values I end up having to work with look like this:

ed_deliveryMethod:Face to Face,ed_location:Alexandria,VA,ed_delivery:Onsite

I need a regex that would parse a key value pair:

  • ed_deliveryMethod:Face to Face
  • ed_location:Alexandria,VA
  • ed_delivery:Onsite

So I need a regex to parse

FacetName:FacetValue

I was doing a split by commas but the comma on the location is throwing things off.

The last comma is optional since there might be just one filter.

I did try a lot of things before asking this question but no success. I'm not good at regex as you can see.

((?<Facet>.+):(?<FacetValue>.+),)+
like image 363
turtlepick Avatar asked Apr 07 '26 18:04

turtlepick


1 Answers

Try the following:

(?<Facet>\w+):(?<FacetValue>.+?)(?=,\w+:|$)

Maybe you need to adjust \w to contain all allowed charactes of your keys.

like image 75
Peter Avatar answered Apr 09 '26 07:04

Peter



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!