正则表达式不匹配,需要帮助找出原因

时间:2022-05-15 21:45:32

The regex is:

正则表达式是:

<td class="description">(?<lineItem>[\w/ -]+)<\/td>\s+<td class="descriptionFormat">(?:[\w\$%\.,()\/ ]*)</td>\s+<td class="amount">[ ]*(?<lineValue>-?\$(?:\d{1,3},?)+\.\d{2})</td>

Ignore case, multi line, and single line are enabled.

忽略大小写,多行和单行。

An example of a statement that matches is:

匹配的语句示例如下:

<td class="description">Fuel Cost Adjustment</td>
<td class="descriptionFormat">18,640 KWH at -$0.00044</td>
<td class="amount">$-1.36</td>

But this one does not match:

但是这个不匹配:

<td class="description">Fuel Cost Adjustment</td>
<td class="descriptionFormat">18,640 KWH at -$0.00044 (25/30 Days)</td>
<td class="amount">$-6.84</td>

I'd really appreciate if anyone could tell me what's wrong.

如果有人能告诉我什么是错的,我真的很感激。

Thank you!

1 个解决方案

#1


0  

(<td class="description">)(?<lineItem>[\w/ -]+)<\/td>\s*<td class="descriptionFormat">(?:[\w\$%\-\.,\(\)\/ ]*)\s*</td>\s*<td class="amount">\s*(?<lineValue>-?\$(-|)(?:\d{1,3},?)+\.\d{2})</td>

should match, but you might consider updating this a bit since html parsing with regex is rather tricky; unless you´re 100% percent sure the inputdata wont change in any way

应该匹配,但你可能会考虑更新这一点,因为使用正则表达式进行html解析相当棘手;除非你100%确定inputdata不会以任何方式改变

#1


0  

(<td class="description">)(?<lineItem>[\w/ -]+)<\/td>\s*<td class="descriptionFormat">(?:[\w\$%\-\.,\(\)\/ ]*)\s*</td>\s*<td class="amount">\s*(?<lineValue>-?\$(-|)(?:\d{1,3},?)+\.\d{2})</td>

should match, but you might consider updating this a bit since html parsing with regex is rather tricky; unless you´re 100% percent sure the inputdata wont change in any way

应该匹配,但你可能会考虑更新这一点,因为使用正则表达式进行html解析相当棘手;除非你100%确定inputdata不会以任何方式改变