Regular expression
Jussi Piitulainen
jussi.piitulainen at helsinki.fi
Wed Jul 26 08:21:29 EDT 2017
Kunal Jamdade writes:
> There is a filename say:- 'first-324-True-rms-kjhg-Meterc639.html' .
>
> I want to extract the last 4 characters. I tried different regex. but
> i am not getting it right.
>
> Can anyone suggest me how should i proceed.?
os.path.splitext(name) # most likely; also: os.path.split, os.path.join
name.rsplit('.', 1) # might do
name[-4:] # "last 4 characters"
name.endswith('.html') # is this what you really want?
This is not a regex job.
More information about the Python-list
mailing list