c# - 正则表达式问题 C#

标签 c# regex

 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/

相关文章:

c# - 使用 NAudio 播放带有自定义编解码器的 WAV

c# - Tridion 2011 核心服务 : Unable to update component with new field using Xml manipulation

c# - IHttpContextAccessor session GetString

javascript - 替换所有出现的子字符串,除了 "之间的字符串

javascript - 如何更改 src 属性的一部分未知

javascript - 仅当不存在嵌套标签时如何获取 <td></td> 之间的内容?

C# WebClient DownloadString 返回乱码

c# - AngleSharp 点击 div

c# - 验证英国电话号码(Regex C#)

python - 使用 Python 和正则表达式查找正确的 URL