This seems like an obvious question but there does not appear to be an answer anywhere at the moment.
I am looking to attempt to process a search query to go into a postgresql full-text search with correct formatting using PHP. I am a bit of newbie to regular expressions and I just can’t seem to work out where to start.
I am looking to take a query along the lines ofSomething AND ("Some Phrase" OR Some Other Phrase) and convert it to 'Something' & (('Some' & 'Phrase')|('Some' & 'Other' & 'Phrase'))
You may be able to point me to a library that does this, I can’t seem to find one although I imagine it is a common problem. Thanks for any help!
This code will parse the example as given and return the requested output. Be aware that it is somewhat brittle: You may need to validate the format of the expression to ensure that it is similar to the format you posted.
You can test your inputs like this: