first occurance of brack

Results 1 to 2 of 2

Thread: first occurance of brack

  1. #1
    Join Date
    Dec 1969

    Default first occurance of brack

    Hi,<BR><BR>I am writing a small program to clean up sql statements for an application using the regular expression in .net. I am stuck on couple of cases.<BR>1. how can you search and replace part of the query that ends before a bracket. for example<BR><BR>select personId from ( select personId from person_tbl ) xx <BR><BR>I want to search and replace the select text inside the bracket. I tried this<BR><BR>(s*selects*.*))<BR><BR>this however does not work all the time. if there is a long query with more than one pair of brackets, it replace everything upto the last bracket.<BR><BR>2. how can you search and replace a query that does not have a from clause. for example.<BR><BR>select personId from ( select personId ) xx <BR><BR>is there a way to know that the subquery does not have a from clause vs one that does?<BR><BR>thanks<BR><BR>Pauli<BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: first occurance of brack

    To capture text which is within parentheses you need to use nested constructs matching to get all of the balancing groups and then, individually parse each group. I&#039;ve written a little article about how you use that construct here:<BR><BR><BR><BR>As for the second part of your query, you could use a Negative Lookahead assertion to check for SELECT statements which contain no FROM clause:<BR><BR> ^select(?!.+?from).+$

Posting Permissions

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