0

我正在制定我公司的新价格表,我需要将所有价格更改为 4%。我正在使用适用于 RegEx 的 InDesign(数字调整器)脚本。在文本中有两种形式的数字:1.200 430 我使用 (\d.\d{3}) 成功更改了第一个,将其乘以 1.04。问题是如果用 (\d{3}) 更改 3 位数字,它也会更改以前的数字,但只更改点之后的部分。我需要一个匹配 3 位数字但不匹配.** 一个,或者两个都匹配的一个,所以脚本可以一次重新计算所有价格。另外,文章编号是这样的:45.62.54,我需要更改一些两位数的价格,所以我需要排除这种字符串或任何前后带有点的两位数!我不是程序员,所以我很难理解正则表达式系统。

4

1 回答 1

0

This regex :

\b\d*\.?\d+\b

// \b\d*\.?\d+\b
// 
// Assert position at a word boundary «\b»
// Match a single digit 0..9 «\d*»
//    Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
// Match the character “.” literally «\.?»
//    Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
// Match a single digit 0..9 «\d+»
//    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Assert position at a word boundary «\b»

Matches an integer or a floating point number with optional integer part.

Also for your first solution :

(?<!\.)\d{3}

// (?<!\.)\d{3}
// 
// Assert that it is impossible to match the regex below with the match ending at this position (negative lookbehind) «(?<!\.)»
//    Match the character “.” literally «\.»
// Match a single digit 0..9 «\d{3}»
//    Exactly 3 times «{3}»

This matches 3 digits who are not preceded by . .

This regex :

\b\d*(?:\.\d+)?\b\s+

Should match only the number. It expects that the numbers are separated by at least one space thus excludes the article numbers 53.44.55 since it's not a valid number. If you have other constraints let me know.

于 2011-10-18T09:59:20.617 回答