다른 정규 표현식에 문제가 있습니다. 이 코드에서 내 코드는 패턴을 찾습니다.문자가없는 한 Python Regex가 일치합니다.
re.compile(r"kill(?:ed|ing|s)\D*(\d+).*?(?:men|women|children|people)?")
그러나 너무 공격적으로 일치합니다. 그것은 '살인'이라는 단어가있는 문장과 일치합니다. 그러나 패턴은 텍스트에서 더 아래쪽 숫자에 도달 할 때까지 계속 수집됩니다. 특히, 일치하는 것입니다 :
killed in an apparent u.s. drone attack on a car in yemen on sunday, tribal sources and local officials said.the men's car was driving through the south-eastern province of maareb, a mostly desert region where militants have taken refuge after being driven from southern strongholds.yemen, where al qaeda militants exploited a security vacuum during last year's uprising that ousted president ali abdullah saleh, has seen an in10
이것은 이후의 동작이 아닙니다. 이 문장을 한 문장 안에 찾을 수없는 경우이 패턴이 실패하기를 바란다.
나는 의사 코드에 구현 노력하고있어 솔루션입니다 :
find instance of 'kill'
if what follows contains a period (\.) before a digit, do not match.
내 구현은 다음과 같습니다 실패
re.compile(r"kill(?:ed|ing|s)\D*(?!:\..*?)(\d+).*?(?:men|women|children|people)?")
가 나는 '보이는 숨김'시도했습니다,하지만 난 너비를 지정해야합니다. 위의 작업을 수행하기 위해 노력하고있는 것은 'kill'의 끝과 일치하며, 그 뒤에 임의의 비 숫자가옵니다. 마침표와 일치하지 않으며, 그 밖의 문자는 내가 따라 오는 자릿수 앞에 따를 수 있습니다.
슬프게도,이 코드는 내 테스트에서 똑같이 작동합니다. 어떤 도움을 주시면 감사하겠습니다.
Breivik과 같은 공격을 계획 하시겠습니까? – alinsoar
haha, no. 신문 기사를 통해보고 있는데 재해로 사망 한 사람의 수를 찾으려고 시도하면 – hyleaus