我对这个程序没有经验,但this应该与javascript一起工作,因此正则表达式的其他功能最小的实现。
\[?\s*(\d+)\s*(?=(?:,\s*\d+)+|\])(?=[^\[]*\]).
\[? # Literal [, zero or 1 times
\s* # Any number (*) of whitespace characters
(\d+) # Any number of digits, one or more (+)
\s* # Any number (*) of whitespace characters
(?= # Positive lookahead, support for possitive lookahead is key to the regex
(?: # Open non-capturing group
,\s*\d+ # Literal ",", any number of whitespace characters,
# digits one or more
) # Close non-capturing group
| # or
\] # Literal "]"
) # Close positive lookahead
(?= # Open another positive lookahead
[^\[]*\] # Any number of characters that are not "[", as long as they're followed by "]".
# This is only a validation check, those characters won't be caught
) # Close positive lookahead
. # Match any character except newline
如果该程序支持可变长度bookbehinds,则可以使用这一点,这只是增加了一个反向预搜索到makesure数目由有效字符前缀为好。
\[?\s*(?<=\[[,\d ]*)(\d+)\s*(?=(?:,\s*\d+)+|\])(?=[^\[]*\]).
如果您的引文格式是100%可靠的[1]
,[12]
,[13, 14, 21]
等,您可以使用simpler version
\[?\s*(\d+)(?=(?:, \d+)|\])(?=[^\[]*\]).
或这,如果你的程序支持可变长度lookbehinds,\[(?<=\[[,\d ]*)(\d+)(?=(?:, \d+)|\])(?=[^\[]*\]).
。
有了这些表情的:你可以改变的最后一个字符,.
,以\]?
看到用逗号[1],[15],[22]
还是分开的引文。
*
在正则表达式的许多香料,lookbehinds-- 如果在所有支撑,必须是一个固定长度的不带量词和所有交替为相同的宽度。例如,(?<=a|1)
将工作,但(?<=a|12)
,(<=a|1+)
或(<=a+)
将失败。量词将应用于后视本身(?<=a)+
编辑:并感谢Rawing输入。
有两件事我不明白:1)为什么这个标记'javascript'?这个AutoBookmark程序能执行javascript吗? 2)“_return_括号内的数字”是什么意思?你只是想用'[1] [2]'或其他的东西(例如为每个正则表达式匹配运行一些代码)来替换所有'[1,2]'的出现? –
我知道......我没有训练,我确信我说的是错的。但是,基本上,是的。这相当于“替换所有事件”。我提出的(不完全回答邮件)是((?<= \ [)|(?<=(\ d,)))(\ d {1,3})''。这太多了,因为文本中可能还有一些数字,我不想要。如果必须,我可以忍受这一点 - 我宁愿有一些额外的错误链接,而不是错过任何。 –