正则表达式更改 InDesign 中的价格

发布于 2024-12-10 15:36:07 字数 341 浏览 1 评论 0原文

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

I'm working on the new pricelist of my company and I need to change all the prices with an increase of 4%.
I'm using a script for InDesign (Number Adjuster) that works with RegEx.
In the text there are number in two forms:
1.200
430
I successfully changed the first one using (\d.\d{3}), multiplying it for 1.04.
The problem is if a change the 3 digits one with (\d{3}) it changes also the previous ones, but only the part after the dot.
I'd need a regex that matches the 3 digits ones but not the .** ones, or alternatevely one that matches both of them, so the script can recalculate all the prices at once.
Also, the articles number are like this: 45.62.54 and I need to change some prices that are two digits, so I need to exclude this kind of string or any two digit number with a dot before or after!
I'm not a programmer so I'm struggling to understand the regex system.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2024-12-17 15:36:07

此正则表达式:

\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»

将整数或浮点数与可选整数部分匹配。

同样对于您的第一个解决方案:

(?<!\.)\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}»

这匹配前面没有 . 的 3 位数字。

这个正则表达式:

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

应该只匹配数字。它期望数字至少由一个空格分隔,因此排除商品编号 53.44.55,因为它不是有效的数字。如果您有其他限制,请告诉我。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文