On 2/18/2014 12:22 PM, Marc Perkel wrote:
Trying to do something complex and not sure how it's done. What I'm looking for is to combine 2 conditions in a single regular expression so that both have to be true for a match. Yes - I know I can make 2 SA rules and combine them but I bet there's a way to do it in one expression. For simplicity here's the challenge.

A chuck of text has to include the word "cat" 5 time and the word "dog" 4 times to be a match. How do you do that?

Take the FSM approach. You have thirty states to deal with, specifically {found X dogs, Y cats | X <- {0..5}, Y <- {0..4}}. The transitions between states should be obvious. Naively translating to a regex, you get a very very long pattern.

http://cs.stackexchange.com/questions/2016/how-to-convert-finite-automata-to-regular-expressions

As John alludes to, though it is technically possible you really don't want to do this. There's much more maintainable and composable ways to write what you need.

Reply via email to