如何排除行吗?在正则表达式 - How to exclude lines with … in regular expression

- 此内容更新于:2015-12-20
主题:

我有下面的表的内容和部分在我的文件:我想提取部分名称和忽视行表的一部分内容。我一直在这个正则表达式:不过,我继续捕捉目录。我怎么能排除....的行字符串?谢谢!

原文:

I have the following table of contents and sections in my file:

1.2 Purpose .................... 8  
1.3 System Overview ............ 8  
1.4 Document Overview .......... 8  
1.5 Definitions and Acronyms ......... 9  
2.1.3.3.8   FOO 
2.1.3.3.9  BAR 
2.1.4 TEST

I'd like to extract the section names and ignore the lines that are part of the table of contents.

I've been trying this regular expression:

^((?:\d{1,2}\.)+(?:\d{1,2})+)\s.+(?!\.\.\.).*$

However, I keep capturing the table of contents lines.

How can I exclude the lines with the .... strings?

Thanks!

楼主:这是逐行。我想让\1包含非TOC的段落编号线。

(原文:It is line by line.I'd like \1 to contain the section numbers from the non TOC lines.)

网友:部分的名称没有后来吗?

(原文:Does the section names do not have ... afterwards?)

楼主:不。他们不。只有TOC行。

(原文:No. They do not. Only the TOC lines do.)

网友:因为之前,和之后,原来的可以选择任何位置它想找到一个不匹配的地方,如果发现任何一个这样的地方,你会得到一个打击。

(原文:Because you had a .+ earlier, and a .* later, the original could actually choose any position it wanted to find a place where (?!\.\.\.) wouldn't match -- and if it found any single such place, you'd get a hit.)

解决方案:
这里的问题是,你只是不包括在一个非常具体的地方;你的负面超前匹配没有超越的位置放置在。考虑相反:……下面的字符与胡萝卜是至关重要的:他们不仅使负面超前应用特定点,但在任何地方。
原文:

The problem here was that you were only excluding .s at a very specific place; your negative lookahead match didn't go beyond the position it was placed in. Consider instead:

^(\d{1,2}(?:\.\d{1,2})*)\s*[^.]*(?!.*\.{3}).*$
#                                  ^^

...the characters with the carrot below them are critical: They make the negative lookahead apply not only at that specific point, but at anywhere after it as well.

楼主:,做到了。谢谢你们!

(原文:That did it. Thank you!)

网友:这是更简单的引擎,我相信:。

(原文:This one is a bit easier for the engine, I believe: ^(\d{1,2}(?:\.\d{1,2})*)\s*(?!.*\.{3,}).*$.)

网友:@stribizhev,好叫——更好的消费任何空格可以使用之前的负面断言;实际上,可以使用任何从考虑non-period内容一样。

(原文:@stribizhev, good call -- better to consume any whitespace available to be consumed before making the negative assertion; actually, could consume any non-period content from consideration the same way.)