I want to replace a query string like this:
SELECT abc,def,ghi,jhk FROM table....
with
SELECT X FROM table....
this should be quite easy and i get the regexp replace to work as expected, but i cant get my expression right.
This is what i have:
rgx = new Regex("SELECT*.FROM");
data = rgx.Replace(data, "SELECT X FROM");
It also does not work in the online evaluator i tried, but i have no clue how it has to be then. And how do i get a modifier in there? I think it should be ungreedy.
I know that this whole thing might seem useless but this is exactly what i want and need to do.
You mixed up the
*and.Also you might want to add some spaces in there, otherwise the regex would also match
SELECTFOOBARFROM.Further more (assuming that C#’s Regexes support non-greediness) I’d make the wildcard non-greedy via a trailing
?.Right now your regex is greedy. As a result your current regex would change this:
into this:
while the correct result would have been this:
Ergo, go with this instead: