Regex for finding valid sphinx fields
Posted
by mlissner
on Stack Overflow
See other posts from Stack Overflow
or by mlissner
Published on 2010-04-20T18:41:03Z
Indexed on
2010/04/20
18:43 UTC
Read the original article
Hit count: 264
I'm trying to validate that the fields given to sphinx are valid, but I'm having difficulty.
Imagine that valid fields are cat, mouse, dog, puppy.
Valid searches would then be:
- @cat search terms
- @(cat) search terms
- @(cat, dog) search term
- @cat searchterm1 @dog searchterm2
- @(cat, dog) searchterm1 @mouse searchterm2
So, I want to use a regular expression to find terms such as cat, dog, mouse in the above examples, and check them against a list of valid terms.
Thus, a query such as: @(goat)
Would produce an error because goat is not a valid term.
I've gotten so that I can find simple queries such as @cat with this regex: (?:@)([^( ]*)
But I can't figure out how to find the rest.
I'm using python & django, for what that's worth.
© Stack Overflow or respective owner