Regular expression condition: letters other than "crfl" at the end of a word or line are deleted?

I tried:

re.sub(r'[^crfl](?=(\.|\,|\s|\Z))', '', val, flags=re.I) 

in line

 car. cupid, fof bob lol. koc coc, cob 

but the result:

 car cupi fof bo lol koc coc co 

I can’t guess why the statement in the title was removed with commas and periods.

As a result, I am for:

 car. cupi, fof bo lol. koc coc, co 
+5
source share
1 answer
 [^crfl.,](?=(\.|\,|\s|\Z)) 

just include ., in the negation list . See the demo.

https://regex101.com/r/yX8zV8/5

or simply

 \w(?<![crlf])\b 

See the demo.

https://regex101.com/r/eB8xU8/1

+2
source

Source: https://habr.com/ru/post/1242172/


All Articles