const string strRegex =
@"(?<city_country>[^.]+) (cca|ca.|ungefähr) (?<price>[\d.,]+) (eur)?";
searchQuery = RemoveSpacesFromString(searchQuery);
Regex regex = new Regex(strRegex, RegexOptions.IgnoreCase);
Match m = regex.Match(searchQuery);
ComplexAdvertismentsQuery query = new ComplexAdvertismentsQuery();
if (m.Success)
while “Agadir ca. 600” is false but “Agadir ca. 600 eur” is true. “eur” is optional but “Agadir ca. 600” is false? Why?
Enclose
eurin parenthesis, like so(eur)?.?matches the preceding character zero or one times. By enclosing it in the parens, it will match the whole word.Also, maybe it is matching the last space before
(eur)?. Try this:@"(?<city_country>[^.]+) (cca|ca.|ungefähr) (?<price>[\d.,]+)(\seur)?"Notice, I removed the last white space and added
\s, which matches any white space including space, tab, form-feed, etc.