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

Thread: Regular Expression pattern - complex pattern syntax

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regular Expression pattern - complex pattern syntax

    I need the regular expression paattern for the following request.

    Source : "abc\\;xysy;xyzablec;yhaxhed\\\\;lkjfsda"

    Pattern : Split the string into arrays by semicolon(;), but the semicolon not followed the slash(\) one or more time.

    Expected output: [bc\\;xysy],[xyzablec],[yhaxhed\\\\;lkjfsda]


    Is this possible, from analyse-- patter executes from left to right, once travels it will never back. Also we can able to union or intersection between the patterens.

    But these topics are not satisfied from my request. Please help me, very urgent


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Regular Expression pattern - complex pattern syntax

    Yes, it is possible. Simply analyze what is needed:

    What can any character before the last one be? Well, it can be any single character except for a semi-colon, or a backslash directly followed by a semi-colon. The pattern then must end with a semi-colon character, or the end of the string. Because these are already consumed in the section before looking for the last character, you don't need to even take it into consideration when writing the pattern for the last character.

    Once you have all the patterns matched, simply trim off the last character if the second to last character isn't a backslash.

    Alternatively, you can leave off any check for what the ending pattern character should be, and instead advance the position to start the next pattern search to include that gap of 1. This removes the need to trim the last "free-standing" semicolon at the end.
    Last edited by helloworld922; June 6th, 2011 at 09:10 AM.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Regular Expression pattern - complex pattern syntax

    Hello SmartAndy,

    Welcome to the Java Programming Forums.

    Please only post each thread once. I have removed your duplicate thread.

    Regarding your question, take a look at this tutorial: http://www.javaprogrammingforums.com...explained.html

    Other useful links:

    Kvalley's RegEx Creator

    Regular Expression Tester
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Regular Expression pattern - complex pattern syntax

    Thank you.

    Ya its possible by using below pattern.
    String[] valueArray= string.split("(?<!\\\\);");

    But i cant understand what this pattern(?<!) explain.. pls help me...

Similar Threads

  1. Regular Expression help
    By medoos in forum Java SE APIs
    Replies: 0
    Last Post: March 19th, 2011, 08:23 PM
  2. 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
  3. a new pattern with a new architecture
    By mcgrow in forum Web Frameworks
    Replies: 0
    Last Post: August 4th, 2010, 03:28 PM
  4. Using Regular Expression (regex) in Java Programming
    By lordelf007 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 14th, 2010, 11:29 AM