drgmak drgmak - 4 months ago 11x
Vb.net Question

Replace regex Match with other value

I have a query like this:

select * from tdirectories where tdirectories.parent in
select max(tdirectories.directoryid) from tdirectories
where tdirectories.ntfsdrivedocuid in
select ntfsdrivedocuid from tntfsdrives, tntfsdrivedocu
where tntfsdrivedocu.ntfsdriveid = tntfsdrives.ntfsdriveid and tntfsdrives.hostid in
select tdocu.hostid from tdocu, tshares
here tdocu.docuid = tshares.docuid
and tdocu.archiv = 0
and tntfsdrivedocu.archiv = 0
and tdirectories.pathhash in (select tshares.pathhash from tshares )

What I want to do is that by using RegEx I want to find this part:

select max(tdirectories.directoryid)

Inside the
can be any value. I want to find it and remove, as result i will have

select tdirectories.directoryid

The regex I have created looks like this:

Regex rgx = new Regex("(select\\s.+select)\\smax\\s*\\((?<VAR>[^)]+)\\)");

But this does not solve my issue. What am i missing?

Jan Jan

You could go for (in free mode):

select       # select literally
\            # a space
max          # max literally
\(([^)]+)\)  # capture anything inside the parentheses

And use the first group ($1), see a demo on regex101.com.