Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex condition: letters except 'crfl' at the end of the word or string are deleted?

Tags:

python

regex

I tried:

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

on string

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

but the result is:

car cupi fof bo lol koc coc co

I don't uderstand, why lookahead assertion deleted commas and dots.

The result I'm for is:

car. cupi, fof bo lol. koc coc, co
like image 751
Andrey Sibiryakov Avatar asked Oct 30 '22 10:10

Andrey Sibiryakov


1 Answers

[^crfl.,](?=(\.|\,|\s|\Z))

just include ., in negation list.See demo.

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

or simply

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

See demo.

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

like image 70
vks Avatar answered Nov 10 '22 22:11

vks