This discussion is archived
4 Replies Latest reply: Dec 7, 2008 7:22 PM by 3004 RSS

Pattern match and Find & Replacement Help

843785 Newbie
Currently Being Moderated
Hello
I am excepting letters from user. Only letters which matches with my requirements are allowed. In the next step I am suppose to replace the letters with options of my choice but I am not able to do it as some times the user enters in capital letter and some times in small letters.

More over if there is a gap after a set of letters then again I am not able to do. Can any one help me in this case?

Here is my code:

if(Pattern.matches(".*[^(y|Y)(k|K)(w|W)(x|X)]+.*",inputStr)){
            //False and so set error message!
            checkErrors(1);
        }else{
            //True and so works
            processStr(inputStr);
        }
Here is find and replace code:
inputStr.replaceAll("w", "L");
Do you think once pattern matches I should go for token iteration?

I am newbie so any help will be appreciated.
Thank you
  • 1. Re: Pattern match and Find & Replacement Help
    3004 Newbie
    Currently Being Moderated
    The first thing you have to do is describe very clearly what your requirements, which you have not done here. I have no idea what you're trying to do.
  • 2. Re: Pattern match and Find & Replacement Help
    843785 Newbie
    Currently Being Moderated
    Okie,

    There is a form where the user enters Strings. I get that String and check for that pattern match. If there is no pattern match then it is an error.

    If the pattern matches then I go for replacing some of the alphabet.

    Lets say, if some one enters " sdfsdf sdfsdf sfsdf" I should be able to replace all f with "O" or "P".This I am able to do but the major problem is to retain the user format.
    lets say he enters like this
    sfsdf sdfsf sdfs
    sfsf
    sfsfs

    I am not able to genterate and out put of this kind in the servlet
    sOsdO sdOsO sdOs
    sOsO
    sOsOs

    More over for small "f" i want to replace with "o" and for "F" I want to replace with "O", how do I do it?
    Thanks for your help
  • 3. Re: Pattern match and Find & Replacement Help
    843785 Newbie
    Currently Being Moderated
    String.replaceAll(...)
  • 4. Re: Pattern match and Find & Replacement Help
    3004 Newbie
    Currently Being Moderated
    merit wrote:
    If the pattern matches then I go for replacing some of the alphabet.

    Lets say, if some one enters " sdfsdf sdfsdf sfsdf" I should be able to replace all f with "O" or "P".This I am able to do but the major problem is to retain the user format.
    lets say he enters like this
    sfsdf sdfsf sdfs
    sfsf
    sfsfs

    I am not able to genterate and out put of this kind in the servlet
    sOsdO sdOsO sdOs
    sOsO
    sOsOs

    More over for small "f" i want to replace with "o" and for "F" I want to replace with "O", how do I do it?
    Thanks for your help
    I still don't get what particular problem you're having.

    If you want to know in general how to replace parts of a string with other strings, then String's replace or replaceAll method.

    If you've tried that and are having problems then you need to show what you've tried (an SSCCE) and spell out exactly what problems you're having.