0

I have a multiline string from which I need to split and get only required texts. I should not count the index manually because the length might change every time.

My Python code

test= "all:qwe:ew1:aq-nps-3:977232323342:isc/isc-04987s4c12399a1sa"
a= test.split()
print(a)

Now I am stuck here on how to proceed further. 

I want to get "aq-nps-3" and "isc-04987s4c12399a1sa" values alone from a string and store it in different variable. Can anyone guide me on further steps? Is it a good way to count index manually or how I can get these required values alone.

Expected results:

a= aq-nps-3
b= isc-04987s4c12399a1sa
5
  • 3
    You need to define a rules of what makes your "required texts" as required Commented Nov 27, 2019 at 10:35
  • sorry I did not get you Commented Nov 27, 2019 at 10:36
  • 1
    I agree with @RomanPerekhrest, Why you need that thing only, Are there any patters for it or identity to extract the text? Commented Nov 27, 2019 at 10:38
  • yes I need that particular texts only for my future validation purpose Commented Nov 27, 2019 at 10:40
  • what if the statement changes to something else? I suggest to make a generic patter instead of just extracting from the string.! Commented Nov 27, 2019 at 10:42

2 Answers 2

2

Looks like you should be splitting by the : character:

 bits = test.split(':')
 a = bits[3]
 b = bits[5]
 print(a, b)
Sign up to request clarification or add additional context in comments.

Comments

0

I was able to crack with below code,

test= "all:qwe:ew1:aq-nps-3:977232323342:isc/isc-04987s4c12399a1sa"
a= (test.split(':')[-1]).split('/')[-1]
print(a)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.