#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Need a Regular Expression pattern in Java


    Hi,

    Thanks in advance for your help. I have to replace a string if it's not available inside any single quote.

    e.g.

    name = 'abc12namexyz234' or name='def234namewsr345name' and name like '%ab123name345rt%'

    In the above I've to replace "name" with "ApplicantEntity.name" but I don't want to replace the string that is available inside the single quote i.e. 'abc12namexyz234'. The result after the replacement should be:



    ApplicantEntity.name= 'abc12namexyz234' or ApplicantEntity.name='def234namewsr345name' and ApplicantEntity.name like '%ab123name345rt%'



    I am trying to find a appropriate regex. But still no success on that. Please Help....



    Thanks,

    Utpal
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    The typical solution is "name" and an assertion that there are an even number of quotes after it. Works so long as you don't break strings over multiple lines.
    Code:
    name(?=([^'\\]+|\\.|'([^'\\]+|\\.)*')*$)

IMN logo majestic logo threadwatch logo seochat tools logo