1

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?

3
  • will it work on any regex? Have you written a test case? Aug 19, 2011 at 16:19
  • Yes it does work on a really basic regex.. I think the issue could be that its partially matching in the Rad Designer App, but then Camel is looking for a full match. If that's the case then maybe I need to investigate whether regex in camel can be switched to partial match of some kind.
    – finoutlook
    Aug 22, 2011 at 13:39
  • Camel is using the JDK reg exp so I suggest to write some java code to test the reg exp to get it working in Java. Aug 23, 2011 at 19:42

2 Answers 2

2

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?

1
  • That's true only if you use the matches() method; find() does substring matching like most other regex tools. However, this is the only reason I can see why that regex would fail, so +1.
    – Alan Moore
    Aug 30, 2011 at 3:12
0

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 .*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.