Converting to uppercase using Perl5Substitution

Discussion in 'Java' started by Sudeep Batra - Bond 007, Apr 7, 2004.

  1. 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
     
    Sudeep Batra - Bond 007, Apr 7, 2004
    #1
    1. Advertising

  2. On 6 Apr 2004 17:22:08 -0700, Sudeep Batra - Bond 007 wrote:

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

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruby
    Replies:
    1
    Views:
    2,555
    Ray Dixon [MVP]
    Jul 31, 2003
  2. Guest

    uppercase

    Guest, Feb 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    500
    Nathan Sokalski
    Feb 20, 2006
  3. Sudeep Batra - Bond 007

    Converting string to uppercase using Perl5Substitution

    Sudeep Batra - Bond 007, Apr 7, 2004, in forum: Java
    Replies:
    2
    Views:
    1,666
    Andrew Thompson
    Apr 8, 2004
  4. natG
    Replies:
    4
    Views:
    9,676
  5. Nige
    Replies:
    7
    Views:
    235
    Thomas 'PointedEars' Lahn
    Nov 17, 2003
Loading...

Share This Page