正则表达式 – 排除字符

huangapple go评论109阅读模式
英文:

Regex - excluding characters

问题

我正在尝试创建一个模式,该模式将忽略从“Всего”单词开始并仅捕获末尾的数字2501,472 -> Всего 191 Короб-шкаф вес БРУТТО 2501,472

另外,我正在尝试包括单词变化可能性 [^Короб-шкаф|Коробка],这在我创建的另一个模式中运行正常

([^Всего]?[^\d]?[^Короб-шкаф|Коробка]\s[^вес БРУТТО\s*] \d,]*)

英文:

I am trying to create a pattern that will ignore starting from Всего word and just will capture the number 2501,472 at the end -> Всего 191 Короб-шкаф вес БРУТТО 2501,472

Also, i am trying to include word change possibilities [^Короб-шкаф|Коробка] which is working fine in another pattern i have created

([^Всего]?[^\\d]*?[^Короб-шкаф|Коробка]\s*[^вес БРУТТО\\s*] \\d,]*)

答案1

得分: 1

将我的评论转换为答案,以便未来访问者更容易找到解决方案。

您可以使用这个替代的正则表达式,它使用一个捕获组来捕获在已知模式之后出现的数字:

\\bВсего\\h+\\d+\\h+(?:Короб-шкаф|Коробка)\\h+вес\\h+БРУТТО\\h+([\\d,]+)

然后使用捕获的第1组来获取包含数字和逗号字符的数字。

英文:

Converting my comment to answer so that solution is easy to find for future visitors.

You may use this alternation regex that uses a capture group where we are capturing number that appears after a known pattern:

\\bВсего\\h+\\d+\\h+(?:Короб-шкаф|Коробка)\\h+вес\\h+БРУТТО\\h+([\\d,]+)

Then use captured group #1 for your number comprising digits and comma characters.

huangapple
  • 本文由 发表于 2020年1月3日 15:11:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定