当前位置: 动力学知识库 > 问答 > 编程问答 >

Python RegEx entire line which starts with given word

问题描述:

I'm trying to create a parser that will scan an entire text for lines that start with either "ACTIE" or "TODO" after which it returns the rest of the line except for the word at the start

Example:

This is an example text

ACTIE this should be returned

more text etc.

should return:

this should be returned

The regex I have created so far is:

\s*(\bACTIE|TODO\b) ([^\n\r]*)

which returns both ACTIE and the line after it as two hits:

ACTIE, this should be returned

Is there any way I can let it drop "ACTIE" or "TODO" at the start and only have it return the rest of the line?

网友答案:

Use a non-capturing group:

\s*(?:\bACTIE|TODO\b) ([^\n\r]*)
分享给朋友:
您可能感兴趣的文章:
随机阅读: