How could I split this text at certain points outside of certain things?
I need to make something that can do:
gettokens("'Hi,,,,','bye'", [',']) #It returns: (["'Hi", "'bye'"], [',']) gettokens("Hello: Bye, ABC:abc", [',',':']) #It returns (["Hello", "Bye", "ABC", "abc"], [":", ",", ":"]) gettokens("\"hello world\", \"700x700+10+20\"", [","]) #It returns (["\"hello world\"", "\"700x700+10+20\""], [","]) gettokens("Hel lo:Cow:: Bye, AB C: a bc", [',', ':']) #It returns (['Hello', 'Cow', 'Bye', 'ABC', 'abc'], [':', ':', ':', ',', ':']) gettokens("\"tH+IS Is a string\"+'This+is also a string'* 8-\"Thi+s /st*rin-gs\"", ["+", "-", "*", "/"]) #It returns (["\"tH+IS Is a string\"", "'This+is also a string'", "8", "\"Thi+s /st*rin-gs\""], ["+", "*", "-"])
I need this gettokens()
function.
I have not been successful in making one though, neither has anyone else so far.
Please help, I need this.
ApoorvSingal
google "How to make a lexer in py"
Coder100
No matter what that's never going to work, suppose you had a string that contained the special character.
RohilPatel
Ur right about that one
@Coder100hg0428
@Coder100
It worked for me: https://repl.it/@Programit/Gettokens#main.py
@Coder100
Coder100
Why would you lex by split?
RohilPatel
That's a fair point
@Coder100
I have created the solution: https://repl.it/@Programit/Gettokens#main.py