finoutlook
finoutlook

Reputation: 2533

Apache Camel Regex Operator not matching

I'm trying to use Apache Camel (with Spring XML) to check if a message body matches a regex:

<when>
    <simple>${body} regex 'https?://(?:www\.)?twitter\.com[^\w]+'</simple>
    <to uri="activemq:queue:test"/>
</when>

So http://www.twitter.com/user in the body of a message should be moved to the 'test' queue.

The regex matches in Rad Regular Expression Designer, but Camel is still not moving the message to the 'test' queue. Any ideas why this isn't working?

Upvotes: 2

Views: 5178

Answers (2)

finoutlook
finoutlook

Reputation: 2533

The solution that worked for me was:

<simple>${body} regex '(?:https?://)?(?:w{3}\.)?twitter\.com(?:/.*|/)?'</simple>

which contains some slight modifications. The biggest is the wildcard .* at the end, so that it matches anything afterwards (as long as it has the slash first).

Thanks for the help and for suggesting the .*

Upvotes: 0

Mike Sokolov
Mike Sokolov

Reputation: 7044

java.util.regex requires a full match, so if that is what Apache Camel uses (?) then your hypothesis is correct. Wouldn't the easiest fix be to put ".*" before and after the regex?

Upvotes: 3

Related Questions