Jump to content
We've recently updated our Privacy Statement, available here ×

How to use regular expressions?


nkrgupta

Recommended Posts

Hi,

I'm trying to display a value after evaluating it with a regular expression. However I'm not sure what is the right way to do that, and hence not getting results. Following is the code I'm using in XML part of the jrxml.

 

<textFieldExpression><![CDATA[(
 

($F{name}.matches(^.*s-)) ?
(
$F{name}.substring(0,12) + "..."
)
:
($F{name})

)]]></textFieldExpression>

Any help would be much appreciated!

Thanks

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I assume what you wanted to do is:

$F{name}.length() >= 12 ? $F{name}.substring(0,12) + "..." $F{name}

Perhaps you have to do an additional check, if "name" is not null first.

I see regex as somehow possible but less efficient and overflow here. But the regex expression would be:

$F{name}.matches("^.{12,}$") ? $F{name}.substring(0,12) + "..." $F{name}

Of course, the null-check remains here as well.

Cheers, Thomas

http://www.ThomasZimmer.net

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...