As always, I'm the worst regex maker in the world. But this time I really tried.
So my goal is to make one regex, that handles search related stuff. Search queries might be something like that:
- stack overflow
- "stackoverflow"
- title="stack overflow"
- type:image title=stack overflow
- stackoverflow type:image
- status:closed type:image title:stack overflow
But it should be able to detect them separately.. And it should be able to detect the quotations for direct match.. Only the title, has to have the search query behind it, but other conditions could be in whatever order.
And now I'm so stuck.. I was managed to do this regex. It works for only status:closed type:image title:stack overflow. The dots between the ()
thingis makes it work. If I replace it with |, then I get the first part matching. But Getting this to work, with all possible query formats is impossible to me.
/(?:(?:status[:](closed|open)).(?:type[:](image|video)).(?:(?:title|author|actor|movie)[:](.+)))/i
Here is the tool, I tried to do this all: http://regexr.com/39an1 my scribble is in there too.
This is for a search engine type thingy. So I hope the outcome from the match, is easy to use inside PHP. Also, I think somebody could very much benefit from this, it would have an solution.
If someone could point me to the right away, with at least the dots vs. | between the main ()
thingies. It feels like | = or, but I want kinda like and-or thing.