如何匹配字符串中未出现在字母后面的每个数字?
我正在尝试编写一个正则表达式,它匹配所有数字,直到第一次出现字母为止,或者换句话说,匹配前面没有字母的任何数字。
"1 & 2 Are numbers" // Matches "1" and "2"
"3 Is a number smaller than 4" // Matches "3"
我本以为类似下面的东西会起作用,但无济于事:
(?<![A-Z])\d
这将用于 Adobe InDesign,据我所知,它具有很好的正则表达式支持。
I'm trying to write a regex that matches all numbers until the first occurrence of a letter or, to put it another way, matches any numbers not preceded by a letter.
"1 & 2 Are numbers" // Matches "1" and "2"
"3 Is a number smaller than 4" // Matches "3"
I would have thought that something like the following would work, but to no avail:
(?<![A-Z])\d
This will be for use in Adobe InDesign, which has pretty good regex support, as far as I can tell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的模式可以查找一行中第一个字母
[a-zA-Z]
之前的所有数字。它在测试字符串中找到 1、2 和 3,但没有找到 4。
Here is a pattern which finds all numbers in a line up to the first letter
[a-zA-Z]
.It finds 1, 2 and 3 in your test strings, but not 4.