I'm trying to parse filters for a search command I'm coding. The user can search using one or more arguments. The values can have spaces (if so, must be wrapped around double quotes). Also, there are several "operators" I've declared, these are: =
(for equals), :=
(for starts with), =:
(for ends with) and *
(for contains).
For example:
name=John name:="John Doe" name*"ohn Do"
Must match: name=John
, name*"John Doe"
, name*"ohn Do"
I've tried using Regex (C#) but it won't match the string when it doesn't contain quotes. This is what I came up with so far:
Regex.Matches(input, "(name(=|:=|=:|\\*)([^\"](\\S+)) | (name(=|:=|=:|\\*)\"([^\"]*)\"))", RegexOptions.IgnoreCase);
Which is basically match the word "name" followed by one of the operators followed by anything up to a space, or the same but up to the closing double quotes. But it doesn't match anything.
In reality I'm replacing "name" with a few keywords inside a foreach
, but for the sake of simplicity, let's just match the word "name".
Anyway, any ideas what I might be doing wrong?