const string strRegex = @"(?<city_country>.+) ?(bis|zu)? (?<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)
{
query.CountryName = m.Groups["city_country"].Value;
query.CityOrAreaName = m.Groups["city_country"].Value;
query.PriceFrom = Convert.ToDecimal(1);
query.PriceTo = Convert.ToDecimal(m.Groups["price"].Value);
}
else
return null;
return query;
我的搜索字符串是“Agadir ca. 600 eur”但是“ca.”不是“bis”或“zu”,正则表达式也是如此。正则表达式有什么问题?我希望正则表达式只有在单词“bis”或“zu”时才为真。
我认为这是破旧的
?(bis|zu)?
最佳答案
Agadir ca.
成为您的 city_country
和 (bis|zu)?
部分被跳过,因为您已将其标记为不需要?
。
关于c# - 正则表达式问题 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6795205/