Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Using Regex to analyse Strings

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Using Regex to analyse Strings

    Hi,

    I created a simple quiz program and I am trying to figure out a method to return 3 types of answer's using regex. The 3 answers would be either fully correct, correct (but spelling error) and partially correct, but still awarded being correct.

    So for an example, the three strings will be correct from the method comparing to the String "Elephants" : 1. "Elephants", 2. "Elephents", 3. "Elephant".

    The 1st string is fully correct, so would return "Correct Answer".

    The 2nd string is correct but spelling error ('a' instead of an 'e'), so will return "Correct although spelled Elephants".

    The 3rd string is partially correct (No 's' at the end), but will return "Answer accepted"

    Could anyone figure out the three types of Regex expressions I could use for this method?

    Thanks much appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Using Regex to analyse Strings

    What about Elefants? Or Elaphants? Or Ellephants?
    How close does the attempted spelling need to be?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Using Regex to analyse Strings

    Oh yes, they would all be correct. One or two spelling errors are OK and will result in being correct. Any more letter errors will be wrong.

    When I get the method correctly running, I will then adjust the closeness of the attempted spelling to the user's ease. But I would like to get a start and correct 1 or 2 letter errors.

    Thanks

Similar Threads

  1. Need some Regex help, please.
    By Josheh in forum Java SE APIs
    Replies: 1
    Last Post: December 15th, 2011, 09:43 PM
  2. help with regex
    By fate0x1 in forum Java SE APIs
    Replies: 1
    Last Post: November 18th, 2011, 04:44 PM
  3. need help with regex
    By o2a1 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 13th, 2011, 08:50 AM
  4. Need help with Regex
    By snytkine in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2010, 07:30 AM
  5. Need help with regEx
    By ptabatt in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 14th, 2010, 11:17 AM