作者:文人博客 | 来源:互联网 | 2023-05-19 13:55
Iamstrugglingwitharegextostopattheendoftheline.我正在努力与正则表达式停止在行尾。Inputlookslikethi
I am struggling with a regex to stop at the end of the line.
我正在努力与正则表达式停止在行尾。
Input looks like this:
输入看起来像这样:
![How text spacing looks in Notepad++](https://www.#.com/imgs/3/1/9/0/35/ecae3493a87f04fa5630ded6100724fe.jpe)
Some lines have values (may contain any characters) after the colons, some don't. There may be spaces either side of the colon, there may not be.
有些行在冒号后面有值(可能包含任何字符),有些则没有。结肠两侧可能有空格,可能没有。
For lines 2 and 4 the following work (i.e. match 12
and 16
respectively):
对于第2和第4行,以下工作(即分别匹配12和16):
Pink\s*:\s*(.*)\n
Red\s*:\s*(.*)\n
But for line 3 (where there is no value to match), a regex using the above syntax returns 16, i.e. reads beyond the end of the line.
但对于第3行(没有值匹配),使用上述语法的正则表达式返回16,即超出行尾的读取。
Can anyone suggest what I'm doing wrong? I'm using VBA.
任何人都可以建议我做错了什么?我正在使用VBA。
1 个解决方案