Regular Expression Commas and Columns
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_deliveryM开发者_高级运维ethod: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>.+),)+
Try the following:
(?<Facet>\w+):(?<FacetValue>.+?)(?=,\w+:|$)
Maybe you need to adjust \w
to contain all allowed charactes of your keys.
Use QueryString.GetValues(key)
, it returns an array of values.
E.g. if you have &filter=category:car&filter=category:motorcycle
as you mentioned in a comment, and you call QueryString.GetValues("filter")
you get an array with elements "category:car"
and "category:motorcycle"
. Then split each element by :
, etc.
No regex needed.
精彩评论