none
RegEx: Cant figure out the needed RegEx RRS feed

Answers

  • This regEx returns exactly what you wrote in your example (without the trailing '):

    (?<=','|\(\s*')[\w\s']*(?='\)|',')


    Matches with this regex for the example-sourcetext:

    text haha'hahaha
    text haha'hahaha
    lala'la

    Thursday, October 9, 2014 10:05 AM

All replies

  • Hi,

    you can use "lookbehind" and "lookahead":

    Regex for the first case: 

    (?<= ).*(?=')

    replace the chars in the lookbehind and lookahead for the other ones.

    Thursday, October 9, 2014 7:30 AM
  • thanks, i going to try this, can you tell me how do i use all three patterns, in one regex, with AND, && or something like that
    Thursday, October 9, 2014 8:17 AM
  • Try this:

    ((?<= ).*(?='))|((?<=\().*(?=\))|(?<= ).*(?=\)))

    Thursday, October 9, 2014 8:49 AM
  • INSERT INTO (id,name) values ( 'text haha'hahaha','lala'la')

    INSERT INTO (id,name) values ('text haha'hahaha')

    i try to get the 3 strings out of the 2 statements:

    1. 'text haha'hahaha'

    2.'lala'la'

    3.'text haha'hahaha'

    when i use ((?<= ).*(?='))|((?<=\().*(?=\))|(?<= ).*(?=\))) on the first insert statement i got

    INTO (id,name) values ( 'text haha'hahaha','lala'la

    Thursday, October 9, 2014 8:55 AM
  • OK, with this exact example of the sourcetext it will be easier to understand what you want to do :-)

    Do you want to get the strings with the ' or without?

    Thursday, October 9, 2014 9:12 AM
  • without ;)

    Thursday, October 9, 2014 10:01 AM
  • This regEx returns exactly what you wrote in your example (without the trailing '):

    (?<=','|\(\s*')[\w\s']*(?='\)|',')


    Matches with this regex for the example-sourcetext:

    text haha'hahaha
    text haha'hahaha
    lala'la

    Thursday, October 9, 2014 10:05 AM
  • it works :;-) can you recommend me a good .net regex tutorial

    one more question with the regex you gave me. what would be the inverted version of this regex?

    that gives me everything else, what the regex "erases"

    the background is, i want to escape the ticks (') in the queries, that access sql won't throw an exception

    • Edited by smokyt Thursday, October 9, 2014 10:39 AM
    Thursday, October 9, 2014 10:29 AM
  • I use the book "Regular Expression Pocket Reference" by O'Reilly. It is an excellent reference.
    Thursday, October 9, 2014 10:59 AM