简体   繁体   English

单个拆分或匹配正则表达式

[英]single split or match regex

9.jul. 9.jul。 3 dni od 205,00 EUR 3 dni od 205,00 EUR

Is it possible with single regex (match opr split) get 205,00 number from string? 是否可以使用单个正则表达式(匹配opr拆分)从字符串中获取205,00的数字? It must be single regex and not 2 or 3 regex which give 205,00 as result. 它必须是单个正则表达式,而不是2或3个正则表达式,其结果为205,00。

string looks like: 字符串看起来像:

 <option value="9.7.2010|3">9.jul. 3 dni od 205,00&nbsp;EUR <option value="23.7.2010|3">23.jul. 3 dni od 205,00&nbsp;EUR <option value="27.8.2010|3">27.avg. 3 dni od 205,00&nbsp;EUR <option value="10.9.2010|3">10.sep. 3 dni od 205,00&nbsp;EUR <option value="24.9.2010|3">24.sep. 3 dni od 205,00&nbsp;EUR <option value="29.10.2010|3">29.okt. 3 dni od 205,00&nbsp;EUR <option value="25.3.2011|3">25.mar. 3 dni od 205,00&nbsp;EUR <option value="15.4.2011|3">15.apr. 3 dni od 205,00&nbsp;EUR </select>

Perhaps 也许

(\d+,\d\d) EUR$

You didn't really specify what the subject looks like in general. 您实际上并没有真正指定主题的总体外观。

There are two possible issues here 这里有两个可能的问题

The space 空间

Is it a space (ASCII 32), or &nbsp; 它是空格(ASCII 32)还是&nbsp; ? Or perhaps it's just any \\s character? 还是只是\\s字符?


The match portion 比赛部分

I'm going to assume that it's just a regular space. 我将假设它只是一个常规空间。 If this is not the case, then substitute it in the following pattern. 如果不是这种情况,则以以下模式替换它。

To match only the numbers portion, you can use \\d+,\\d\\d(?= EUR) . 要仅匹配数字部分,可以使用\\d+,\\d\\d(?= EUR) This uses lookahead (?=___) so you only match the portion that you're interested in. 这会使用前瞻(?=___)因此您只匹配您感兴趣的部分。

The other option is to match (\\d+,\\d\\d) EUR and then extract Groups[1] . 另一种选择是匹配(\\d+,\\d\\d) EUR ,然后提取Groups[1]

Related questions 相关问题

References 参考

Your attempt of (\\d+,\\d\\d) EUR (hopefully you weren't actually typing in &nbsp; ) should work, but you have to access group 1 out of the result to get just what's in the parentheses. 您尝试(\\d+,\\d\\d) EUR (希望您实际上没有在&nbsp;键入)应该可以,但是您必须从结果中访问第1组以获取括号中的内容。 For example: 例如:

Regex regex = new Regex(@"(\d+,\d\d) EUR");
Match match = regex.Match("9.jul. 3 dni od 205,00 EUR");
string cashString = match.Groups[1].Value;

The &nbsp; &nbsp; will most likely be converted to ASCII 160 (html decoded), which is not the same as space. 将很可能会转换为ASCII 160(经HTML解码),与空格不同。 Using \\s+ will match no breaking spaces as well as normal space, tab and line feed/carriage return. 使用\\ s +将不匹配任何空格,普通空格,制表符和换行符/回车符。

If it's not decoded then you should be able to use &nbsp; 如果未解码,则应该可以使用&nbsp; instead of \\s+. 而不是\\ s +。

(\d+,\d+)\s+EUR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM