Converting to uppercase using Perl5Substitution

  • Thread starter Sudeep Batra - Bond 007
  • Start date
S

Sudeep Batra - Bond 007

Hi,

We are using the following piece of code for Perl5Substitution.

public String substitute (String regExp, String sub, String input)
throws DatafileException {
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
try {
pattern = compiler.compile(regExp);
} catch(MalformedPatternException e){
String errorMessage = "Bad pattern. " + e;
log.error(errorMessage);
throw new DatafileErrorException(errorMessage);
}
// Perform substitution
return Util.substitute(matcher, pattern, new
Perl5Substitution(sub, 0),input,99);
}

Lets say we want to convert a string such that every word should begin
with "A", then if we pass the following values as parameters to the
above, it works for us.

regExp = (\w+)
sub = A$1

This converts a string "Preferred Stock" to "APreferred AStock".

However, we are not able to find a way to convert the string to
uppercase. The following regular expression in perl script works fine
for us.
$variable=~ s/(\w+)/uc($1)/ge;

But we are not able to reproduce the same to work with
Perl5Substitution. \U doesnt seem to work even.

If anyone can suggest what we should pass as the regular expression
and the substitution string so that we get the desired, that would be
really appreciated.

Thanks
Sudeep
 
A

Andrew Thompson

We are using the following piece of code for Perl5Substitution.

What a coincidence, so is some guy over
on c.l.j.help. Maybe you should get in
contact with him, he might have the answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top