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 2 of 2

Thread: Pattern, regex (regular expression) case sensitivity question

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Pattern, regex (regular expression) case sensitivity question

    i have a clarification answer with a simple case sensitivity question with the code below

    import java.util.regex.Pattern;
     
    public class NewClass6 {
     
        public static void main(String[] args) {
     
            Pattern patt = Pattern.compile("[aeiou]", Pattern.CASE_INSENSITIVE);
            String temp = "A";
     
            if (temp.matches(patt.pattern())) {
     
                System.out.println("MATCH!");
            }
        }
    }

    given that i already using Pattern class doing a bussiness with the Matcher(Pattern-matching),
    in this case the String object(temp) that refers to a string value doesnt matches the pattern even if it has been compiled in a
    CASE_INSENSITIVE manner..

    is it because the statement patt.pattern() ONLY RETURNS a pattern, but the case sensitivity manner doesnt/cannot do anything?


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Pattern, regex (regular expression) case sensitivity question

    is it because the statement patt.pattern() ONLY RETURNS a pattern
    Yes. You can include a case-insensitive switch in the pattern instead of using the separate flags int. See the 'Special constructs' in the API doc.

  3. The Following User Says Thank You to Sean4u For This Useful Post:

    chronoz13 (September 7th, 2011)

Similar Threads

  1. How to remove the regular expression from a string ?
    By srimanta in forum Java Theory & Questions
    Replies: 5
    Last Post: July 20th, 2011, 03:07 PM
  2. Regular Expression pattern - complex pattern syntax
    By SmartAndy in forum Algorithms & Recursion
    Replies: 3
    Last Post: June 7th, 2011, 04:40 AM
  3. Regular Expression help
    By medoos in forum Java SE APIs
    Replies: 0
    Last Post: March 19th, 2011, 07:23 PM
  4. Simple Hashsets and regular expression problem !
    By burningflower in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2011, 01:43 PM
  5. Using Regular Expression (regex) in Java Programming
    By lordelf007 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 14th, 2010, 10:29 AM