0

I wrote this regex that allows you to match the table name. The problem is that it also matches the table fields ( AAA_BBB_CCC_DDD ).

I'd like it to not match field tables that is after a SELECT.

(^|,?\s*)([A-Z]+(_[A-Z]+){2,})(,?\s*|$)

Thank you.

smottt
  • 3,272
  • 11
  • 37
  • 44
jeyGey
  • 161
  • 3
  • 15
  • Please post some examples of what you want to match and what you do not want to match,. – npinti Apr 24 '15 at 09:28
  • For example : AAA_BBB_CCC_DDD => MATCH AAA_BBB_CCC_DDD, AAA_BBB_CCC_DDD => MATCH AAA_BBB_CCC_DDD ALIAS1, AAA_BBB_CCC_DDD ALIAS2, => MATCH (SELECT FIELD_NAME_EXAMPLE, MAX(ID) AS TOTO FROM AAA_BBB_CCC_DDD GROUP BY FIELD_YEAR_EXAMPLE => WARNING Match with FIELD_NAME_EXAMPLE and FIELD_YEAR_EXAMPLE. I don't want. – jeyGey Apr 24 '15 at 09:30
  • Please provide more context. Actual data would help as well. – npinti Apr 24 '15 at 09:38
  • I have this request : ODS_HIST_PS_AF_C_APPTMNT ,(SELECT AF_CONTRACT_ID,MAX(EFFDT) AS EFFDT FROM ODS_HIST_PS_AF_C_APPTMNT GROUP BY AF_CONTRACT_ID ) REQ_MAX I want get only "ODS_HIST_PS_AF_C_APPTMNT", not "AF_CONTRACT_ID ". – jeyGey Apr 24 '15 at 09:41
  • 1
    Please, edit your question and add these examples. – Toto Apr 24 '15 at 09:42
  • 1
    I tried to edit your question in order to improve the meaning. If I missed what you meant, feel free to edit it again but please watch for grammar and typos this time. Also, people may want additional information from you in order to understand your question. That means you should edit your question with that additional info, not pass a new comment here. Your code belongs to your question, they're not a comment after all. And, welcome to the community ;) – ilter Apr 24 '15 at 09:43

1 Answers1

0
string request = "ODS_HIST_PS_AF_C_APPTMNT ,(SELECT AF_CONTRACT_ID,MAX(EFFDT) AS  EFFDT FROM ODS_HIST_PS_AF_C_APPTMNT GROUP BY AF_CONTRACT_ID ) REQ_MAX";

string pattern = @"(^|,?\s*)(?<!(SELECT\s+|BY\s+))([A-Z]+(_[A-Z]+){2,})(,?\s*|$)";

foreach (Match match in Regex.Matches(request, pattern))
{
    s.Add(match.Value);
}

This returns me the following table names :

ODS_HIST_PS_AF_C_APPTMNT => OK

F_CONTRACT_ID => NO (FIELD)

F_CONTRACT_ID, => NO (FIELD)

ODS_HIST_PS_AF_C_APPTMNT => OK

Regex :

"(^|,?\s*)(?<!(SELECT\s+|BY\s+))([A-Z]+(_[A-Z]+){2,})(,?\s*|$)"

I find this : Regex lookahead, lookbehind and atomic groups

Community
  • 1
  • 1
jeyGey
  • 161
  • 3
  • 15