Hi;

If I have a srt file (lines in similar format given below).

42
00:02:21,085 --> 00:02:22,709
Just tell Cuddy you've 
got an urgent case.

43
00:02:22,709 --> 00:02:24,680
- You had to leave early.
- That would be lying.

44
00:02:24,680 --> 00:02:26,119
And that would be wrong.

I would like to know if there is some possible way to distinguish between numeric and characters so that we can compare all digits (0-9) and words (a-z,A-Z).

Recommended Answers

All 3 Replies

Like this, using string methods that can be applied on a line-by-line basis:

>>> '42'.isdigit()
True
>>> 'Test'.isdigit()
False
>>>

Hi JLM

The mentioned code will only do for a sinlge line matching whereas I want to compare thousands of lines in a file which start with different numeric combination and alphabets combination and want to extract lines with only alphabets.
Is there some possible way out? Lik could you compare all digits '0,1,2,3,4,5,6,7,8,9' 'a,b,c,...,z; and do extraction on this base.

I provided an answer to the question that you asked, which was

I would like to know if there is some possible way to distinguish between numeric and characters

Now it is up to you to take that principal and implement it in a simple loop to finish this task. We're not here to create custom solutions for you, we simply help when you get stuck and teach you how to teach yourself to program. Please read the site policies and forum guidelines, as well as all posted announcements before posting.

It would also help if you tried searching to see if other people have already had the same question answered (HINT: they have).

commented: good point +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.