Intentar hacer coincidir la oración completa de un documento que contiene ciertas palabras, incluso si la oración ocupa varias líneas.
Mis intentos actuales solo capturan la oración si no se extiende a las siguientes líneas.
^.*\b(dog|cat|bird)\b.*\.Utilizando ECMAScript.
Cuando no se esperan abreviaturas en la entrada, use
/\b[^?!.]*?\b(dog|cat|bird)\b[^?!.]*[.?!]/giVer prueba de expresiones regulares .
EXPLICACIÓN
-------------------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char -------------------------------------------------------------------------------- [^?!.]*? any character except: '?', '!', '.' (0 or more times (matching the least amount possible)) -------------------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char -------------------------------------------------------------------------------- ( group and capture to \1: -------------------------------------------------------------------------------- dog 'dog' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- cat 'cat' -------------------------------------------------------------------------------- | OR -------------------------------------------------------------------------------- bird 'bird' -------------------------------------------------------------------------------- ) end of \1 -------------------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char -------------------------------------------------------------------------------- [^?!.]* any character except: '?', '!', '.' (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- [.?!] any character of: '.', '?', '!'