【问题标题】:Regular Expression Syntax: 1Words, one : and 2-3 digits [duplicate]正则表达式语法:1个单词,一个:和2-3个数字[重复]
【发布时间】:2019-07-03 20:34:45
【问题描述】:

我正在尝试从 csv 中搜索并删除一些数据。使用 Sublime Text 3 程序一次文件。我找不到合适的,也无法将其组合在一起,这很有效。

应该找到:UVP: 59,99 或 UVP: 159,99

1 个字:UVP 1个符号:“:” UVP: 和 59,00 或 159,99 之间有 1 个空格 和 2 或 3 位数字,然后是逗号和 2 位数字

名单:

UVP:32,99 UVP:324,42 UVP: 321,33 UVP: 19,99

任何想法如何建立一些正则表达式?

【问题讨论】:

  • 你尝试过哪些模式?

标签: regex csv sublimetext3


【解决方案1】:

正则表达式是UVP:\s\d{2,3},\d{2}

使用 perl 它看起来像这样:

echo "UVP: 32,99 UVP: 324,42 UVP: 321,33 UVP: 19,99" | perl -ne 's/UVP:\s\d{2,3},\d{2}/-/g;print'
- - - -

正则表达式的解释:

UVP: matches the characters UVP: literally (case sensitive)
\s matches any whitespace character (equal to [\r\n\t\f\v ])
\d{2,3}
matches a digit (equal to [0-9])
{2,3} Quantifier — Matches between 2 and 3 times, as many times as possible, giving back as needed (greedy)
, matches the character , literally (case sensitive)
\d{2}
matches a digit (equal to [0-9])
{2} Quantifier — Matches exactly 2 times
Global pattern flags
g modifier: global. All matches (don't return after first match)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-19
    • 2018-10-14
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多