Если вы хотите также обернуть слово сразу после not
или never
, вам нужно расширить это регулярное выражение,
\b(?:never|not)\s+[a-zA-Z]+
Здесь \s+
будет соответствовать одному или нескольким пробелам и[a-zA-Z]+
будет соответствовать одному английскому слову, содержащему один или несколько символов.
Regex Demo
Демонстрация кода Python
import re
s = '''He jests at scars that never felt a wound. JULIET appears above at a window But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun. Arise, fair sun, and kill the envious moon, Who is already sick and pale with grief, That thou her maid art far more fair than she: Be not her maid, since she is envious; Her vestal livery is but sick and green And none but fools do wear it; cast it off. It is my lady, O, it is my love! O, that she knew she were! She speaks yet she says nothing: what of that? Her eye discourses; I will answer it. I am too bold, 'tis not to me she speaks: Two of the fairest stars in all the heaven, Having some business, do entreat her eyes To twinkle in their spheres till they return. What if her eyes were there, they in her head? The brightness of her cheek would shame those stars, As daylight doth a lamp; her eyes in heaven Would through the airy region stream so bright That birds would sing and think it were not night. See, how she leans her cheek upon her hand! O, that I were a glove upon that hand, That I might touch that cheek!'''
print(re.findall(r'\b(?:never|not)\s+[a-zA-Z]+', s))
Отпечатки,
['never felt', 'not her', 'not to', 'not night']
Редактировать: Как вы сказали, вы хотите отменить матчи, за которыми следует пробел и a
символ, вы можете использовать отрицательный взгляд вперед и расширить текущее регулярное выражение следующим образом:
\b(?:never|not)\s+[a-zA-Z]+\b(?! a\b)
Здесь я использовал \b
до отрицательного взгляда, чтобы избежать частичного совпадения слова и \b
после a
в отрицательном ключе избегает совпадения слов, которые не просто a
, но что-то более похожее на add
или and
и т. Д.
Regex Demo, где совпадения отбрасываются, если за ними следует пробели a
символ