I am new to Python, have been watching videos on Youtube and trying to learn.
I am trying to substring a text between two spaces from a line. Let me explain, what exactly I am trying.
1) I have a text like mentioned below:
CREATE TABLE DATABASENAME.TABLENAME AS SELECT ....
2) Now from the above text I want to retrieve only DATABASENAME.TABLENAME
3) So I want to extract text between second space and third space, ie. I want to extract text between index numbered 13 and 35, but on basis on spaces.
Can anyone help? Please.
string='CREATE TABLE DATABASENAME.TABLENAME AS SELECT'
extract=string.split(' ')[2]
You can split the string into list of words based on spaces then get the elements by index in this case it's 2.
s = 'CREATE TABLE DATABASENAME.TABLENAME AS SELECT'
print(s.split(' ')) #['CREATE', 'TABLE', 'DATABASENAME.TABLENAME', 'AS', 'SELECT']
print(s.split(' ')[2]) #DATABASENAME.TABLENAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With