Is there a way to search, from a string, a line containing another string and retrieve the entire line?
For example:
string =
qwertyuiop
asdfghjkl
zxcvbnm
token qwerty
asdfghjklñ
retrieve_line("token") = "token qwerty"
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
|
you mentioned "entire line" , so i assumed mystring is the entire line.
however if you want to just get "token qwerty",
|
||||
|
|
|
If you prefer a one-liner:
|
|||||
|
|
With regular expressions
|
||||
|
|
you can also get the line if there are other characters before token
The above works like grep token on unix and keyword 'in' or .contains in python and C#
http://pythex.org/ matches the following 2 lines
|
||||
|
|