Results 1 to 2 of 2
  1. #1
    joe robles is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default Regex search and replace

    Hi all,

    I am new to java 6 regex.

    I have a string with the following content ( each line separated by \r\n).

    Existing string:
    aaaa|
    TEST|x||y|z|""|cccc|bbb|"
    xxxx|
    TEST|x||y|z|Something|cccc|bbb|";
    TEST|x|ST|y|z|""|cccc|bbb|";
    TEST|x||y|z|""XYZ|cccc|bbb|";
    TEST|x||y|z|Y""|cccc|bbb|";
    The expected strign content:
    aaaa|
    TEST|x||y|z||cccc|bbb|
    xxxx|
    TEST|x|ST|y|z|Something|cccc|bbb|
    TEST|x|ST|y|z|""|cccc|bbb|
    TEST|x|ST|y|z|""XYZ|cccc|bbb|
    TEST|x|ST|y|z|Y""|cccc|bbb|
    Basically, if the content between 2nd and 3rd occurance of | is blank and if the content betweeen 5th and 6th occurance of | is "", then make it blank.(Ex: Line 2 in the EXISTING STRING)
    Also if the content between 5th and 6th occurrence is not empty and not "" then if the content between 2nd and 3rd occurance of | is blank make it ST.(eX: Line 4,6,7 in existing string)
    In other scenarios, nothing needs to be changed.
    How to make it possible with Regex replaceall or Pattern/match.

    I tried few things but in vain.

    Please help as I have a dealine to meet.

    Thanks a ton in advance.
    Last edited by joe robles; 09-25-2010 at 09:20 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

Similar Threads

  1. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 02:42 AM
  2. Replies: 0
    Last Post: 11-04-2009, 10:09 PM
  3. Replies: 0
    Last Post: 10-29-2009, 10:28 AM
  4. Replies: 5
    Last Post: 08-26-2008, 04:43 PM
  5. Replies: 2
    Last Post: 08-18-2008, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •