Results 1 to 6 of 6

Thread: Regex problem in construction

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Regex problem in construction

    Hello.
    I have a problem in constructing my regex, I took in the String source following:
    Code:
    [R_RECEVABLE] =''OR ([R_RECEVABLE] = 'O' AND [R_PDL_ETAT] ='') OR ([R_RECEVABLE] = 'O' AND [R_PDL_ETAT] = 'S' AND [AFF_K_PREV_FRN] ='')
    And I would have a result like:
    Code:
    -> [A_AECEVABLE] =''
    -> OA
    -> [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] =''
    -> OA
    -> [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] = 'S' AND [AFF_K_PAEV_FAN] =''
    Now I use the following regex:
    Code:
    String rBloc = "([^\\(\\)]+)";
    And I get the following result:
    Code:
    -> [A_AECEVABLE] =''OA
    -> [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] =''
    -> OA
    -> [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] = 'S' AND [AFF_K_PAEV_FAN] =''
    Can you help with this. Thanks in advance.
    Last edited by Miles Runner; 04-02-2010 at 03:58 AM.

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    Re: Regex problem in construction

    Hello,
    I have trouble in understanding the logic of your cutting and even the logic of the string that you try to cut (an odd number of quotes that overlap with the parentheses) I think more explanation will be highly appreciated. An even you can post the error what you are getting after compiling the program. The information which you have posted is too less, so more information is needed.

  3. #3
    Join Date
    Dec 2009
    Posts
    292

    Re: Regex problem in construction

    Hi,
    The cutting chain is my block is like an if / else normal with parentheses, and within the brackets, the variable would. And therefore, I need to cut the chain, whether I should take into account all the variables, or if it's just a chain of OR and then I stop when the first is good. I think i do not have much idea about it, so if you have an other alternative for this, then please do post back. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    333

    Re: Regex problem in construction

    Hello,
    I think, if you post your code it will be better for our understanding.
    So if I understand you want to cut into pieces which are either:
    - A comparison: [xxx] = 'y'
    - A group in parentheses: (zzzzzzzzzzz)
    - An operator AND or OR
    It could do this with regular expression (\ [.*? \]'.*?')|( = \ (.*? \)) | (OR | AND)

  5. #5
    Join Date
    Dec 2009
    Posts
    292

    Re: Regex problem in construction

    Hello,
    It works great, thanks for that. But I have just one problem, when I retrieve a block, I'd like to avoid having the brackets around it, so instead of having a result like this:
    Code:
    [A_AECEVABLE] =''
    OA
    ([A_AECEVABLE] = 'O' AND [A_PDL_ETAT] ='')
    AND
    ([A_AECEVABLE] = 'O' AND [A_PDL_ETAT] = 'S' AND [AFF_K_PAEV_FAN] ='')
    Have something that looks like this:
    Code:
    [A_AECEVABLE] =''
    OA
    [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] =''
    AND
    [A_AECEVABLE] = 'O' AND [A_PDL_ETAT] = 'S' AND [AFF_K_PAEV_FAN] =''
    I tried to edit a regex can be, but I can not see any parenthesis I must "ensure" to get the expected result.

  6. #6
    Join Date
    Nov 2009
    Posts
    356

    Re: Regex problem in construction

    Hello,
    To avoid capturing parentheses should be: (\ [.*? \] ='.*?')| \ ((.*?) \) | (OR | AND) and find each one has 3 groups which would capture one is not null:
    - Group 1 if we make a comparison: [xxx] = 'y'
    - Group 2 if they are dealing with a group in parentheses: (zzzzzzzzzzz)
    - Group 3 if they are dealing with an AND or OR
    Group 2 contains the result without parentheses. Try this and then compile the program and see what is the result. If you have any queries then post back adn we will try to solve the same.

Similar Threads

  1. IP address regex problem with preg_match_all
    By Leilaa in forum Software Development
    Replies: 2
    Last Post: 12-04-2012, 06:54 PM
  2. Problem in using regex in java program.
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 05:39 PM
  3. Problem in matching Regex
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 04:12 AM
  4. Problem with Regex in returning string
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 03:37 AM
  5. Problem with construction of a query
    By KAILEY in forum Software Development
    Replies: 3
    Last Post: 01-10-2009, 10:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,499,958.84087 seconds with 17 queries