Question: I am working on Jasper Reports using IReport. I want to convert the amount to Words such as 1500 to One thousand five hundred.

I retrieve the numbers from the database and print it on the report. At the end I want the final value to be converted to Words.

Is there any method in Jasper Reports to do this? I have found a Java class to do that. If there's any method in Jasper report, how can I call Java method from jasper report to convert the numbers to letters

Answer: 
Well here is a method that finds any `)` followed by a capital letter and inserts a newline after the `)`:

```
def format(s)
    s.gsub(/\)(?=[A-Z])/, ")\n")
end

```

The `/` starts the regular expression.

The `\)` matches any right parenthesis in the string. The slash is needed because `)` has a special meaning in regular expressions, so it needs to be escaped.

The `(?=[A-Z])` is a positive [lookahead](http://www.regular-expressions.info/lookaround.html) assertion, asserting the the parenthesis is followed by a capital letter.

The second `/` ends the regular expression.
```
def format(string)
  string.sub(/(\d\))/, '\1' + "\n")
end

p format("M Rahim (C)(W): 61(97)S A Hasan: 51(68)") #=> "M Rahim (C)(W): 61(97)\nS A Hasan: 51(68)"
p format("R Taylor (C): 76(160)B Watling: 16(26)")  #=> "R Taylor (C): 76(160)\nB Watling: 16(26)"

```