Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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

Threaded View

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Regular Expression (regex) in Java Programming

    Hiii all,

    I'm new in using Regular Expression in Java.

    For example, I have String s like this:

    String s = "Why John Smith and Alan Smith and Nick Gates are the same?"

    How can I get sub-strings as "John Smith", "Alan Smith", "Nick Gates" - (names of people - with first upper character) from s by using regex?

    I try to use regex in Java, but It totally doesn't work.

    This is my code:
    /*
    String EXAMPLE_TEST = "Why John Smith and Alan Smith and Nick Gates are the same?";
    System.out.println(EXAMPLE_TEST.matches("([A-Z]&&[a-z])"));
    String[] splitString = (EXAMPLE_TEST.split("([A-Z]&&[a-z])"));
    System.out.println(splitString.length);
    for (String string : splitString) {
    System.out.println(string);
    }

    */


    Please help me to have exact "regex" in this case.

    Thanks all in advance!
    Last edited by helloworld922; May 13th, 2010 at 08:42 AM. Reason: please use [code] tags


Similar Threads

  1. Urgent need a java regex pattern
    By mallikarjun_sg in forum Java Theory & Questions
    Replies: 1
    Last Post: May 6th, 2010, 05:51 AM
  2. Illegal Start of Expression Error. Any help is appreciated.
    By SKhoujinian91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 8th, 2009, 12:57 AM
  3. Help creating expression tree
    By nellaf in forum Java SE APIs
    Replies: 1
    Last Post: December 3rd, 2009, 08:54 AM
  4. Creating an Expression Tree
    By vluong in forum Collections and Generics
    Replies: 0
    Last Post: November 28th, 2009, 11:41 PM
  5. [SOLVED] Java Regular Expressions (regex) Greif
    By username9000 in forum Java SE APIs
    Replies: 4
    Last Post: June 11th, 2009, 05:53 PM