Find Questions…

Close ×
First time here? Check out the FAQ!

regex in velocity template

Jan Post asked this question · 26 karma ·

I'm trying to accomplish a regex test in velocity. However, I can't get to work. What am I doing wrong?

My code:

#set( $str = "$issue.reporter")






Now reporter is, but still this test always returns false. The regex is tested in an online regex tester! What would the proper way to do regex testing on strings in a Velocity template?


2 Answers:

Igor Sereda · 4,292 karma ·

1. You need to have \\b instead of /b (two backslashes instead of one for escaping).

2. "matches()" tests the whole string, so you need to match against ".*\\\\b.*"

Jan Post · 26 karma ·

Thnx, got it working with ".*".

Sergey Markovich · 720 karma ·

Hi Jan,

Velocity inherits regex syntax from Java language.

You can have a look at the overview in the documentation here:

I think your code should check something like #if($str.matches(""))

Jan Post · 26 karma ·

combining both answers did the trick. thnx

Looking for something else?

Find Questions…

or Browse other questions tagged:

or Ask a Question