Find something after a key words | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Find something after a key words

I want to find something after a key word or sentence example: here is my index number 123456 I want to return 123456

6th Feb 2018, 9:09 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
5 Answers
+ 3
So you want to find 123456 inside of other text? Sounds like a regular expression job. Can you provide existing code or sample input, what keyword is being searched for and what output you want if any?
6th Feb 2018, 10:23 AM
SQrL
SQrL - avatar
+ 3
I don’t have a regex solution, but python find might be more appropriate, depending on the context. s = "I want to find index number123456" s2 = "index number" i=s.find(s2)+len(s2) print ("Location of end of index number:",i) print (s[i:]) https://code.sololearn.com/cRSN8vQB1zlk/?ref=app EDIT: Autocorrect had made “regex” into “reflex”
6th Feb 2018, 1:47 PM
SQrL
SQrL - avatar
+ 1
I mean that the regex may be for example 'index number' so the result should be what come after 'index number' which is 123456 😊
6th Feb 2018, 11:43 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
something like this: r' here is my index number (\d{,6})' and then using match.group(0)
3rd Jun 2018, 5:22 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar
3rd Jul 2018, 5:59 PM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar