PLEASE NOTE:
In Splitting text into lines with pyparsing it is about how to parse a file using a single token at the end of a line which is \n
that is pretty easy peasy. My question differs as I have hard time ignoring last text which is started before :
and exclude it from free text search entered before filters.
On our API I have a user input like some free text port:45 title:welcome to our website
and what I need to have at the end of parsing is 2 parts -> [some free text
, port:45 title:welcome
]
from pyparsing import *
token = "some free text port:45 title:welcome to our website"
t = Word(alphas, " "+alphanums) + Word(" "+alphas,":"+alphanums)
This does give me an error:
pyparsing.ParseException: Expected W:( ABC..., :ABC...), found ':' (at char 21), (line:1, col:22)
Because it gets all strings up to some free text port
and then :45 title:welcome to our website
.
How can I get all data before port:
in a separate group and port:....
in another group using pyparsing?