Regular expression and match/group

  • Thread starter Thread starter Nicolas
  • Start date Start date
N

Nicolas

This is the string source:
SELECT DocUNID, [Name] AS 'Dép./Prov.', StateCode AS 'Code', name_en AS
'English', name_fr AS 'Français', name_es AS 'Español', name_it AS
'Italiano', name_pt AS 'Português', name_de AS 'Deutsch' FROM StateCity WHERE
(ApplyTo='S' AND CountryCode='CA') ORDER BY 'Dép./Prov.' Asc;

These are the reg exp:
((.* FROM )(?<TABLE>[\w';./\[\]]*)((\s)|()))
((.* WHERE )(?<WHERE>[\w\s'%=;./\[\]\(\)]*)(( ORDER BY )|()))
((.* ORDER BY )(?<ORDERBY>\[[\w\s';./\[\]]*\]|'[\w\s;./\[\]]*')(( ASC)|(
DESC)|()))

The idea is to extract the TABLE (FROM) 'Name" the WHERE Clause syntax and
the ORDER BY criteria string. I will then check if there is a regexp match
group (Success) for each one in my matches.
The problem is that if in the source string there is not WHERE Clause or
ORDER BY, it return nothing however the FROM is there and I need it. I would
not like to run 3 regexp match if I can only use one.

Thanks for the help
 
This syntax seems to work for now:
(.* FROM )(?<TABLE>[\w';./\[\]]*)((.* WHERE
)(?<WHERE>[\w\s()'=;./\[\]]*)|())((.* ORDER BY
)(?<ORDERBY>[\w\s';./\[\]]*)|())(( [ADESCadesc;]*)|())" '"^(.* FROM
)(?<TABLE>[\w';./\[\]]*)|(.* WHERE )(?<WHERE>[\w\s'%=;./\[\]]*)|(.* ORDER BY
)(?<ORDERBY>\[[\w\s;./\[\]]*\]|'[\w\s;./\[\]]*')
 
Back
Top