Regular expression

Paul Barry paul.james.barry at gmail.com
Wed Jul 26 08:05:23 EDT 2017


Is this what you are after?

*>>> *data = 'first-324-True-rms-kjhg-Meterc639.html'

*>>> *extension = data.find('.html')

*>>> *extension

33

*>>> *data[extension-4:extension]

'c639'

On 26 July 2017 at 13:00, Johann Spies <johann.spies at gmail.com> wrote:

> On 26 July 2017 at 13:52, Kunal Jamdade <kunal123jamdade at gmail.com> wrote:
> > 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.?
>
> What have you tried?
>
> Why do you need regular expression?
>
> >>> s = 'first-324-True-rms-kjhg-Meterc639.html'
>
> >>> s[-4:]
> 'html'
>
> Regards
> Johann
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Paul Barry, t: @barrypj <https://twitter.com/barrypj> - w:
http://paulbarry.itcarlow.ie - e: paul.barry at itcarlow.ie
Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.



More information about the Python-list mailing list