drgmak drgmak - 1 year ago 122
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download