troubleshooting Question

Regular expression to trim prefix from a name

Avatar of Frosty555
Frosty555Flag for Canada asked on
Visual Basic ClassicVB ScriptRegular Expressions
2 Comments1 Solution630 ViewsLast Modified:
Is it possible to do this with a regular expression replacement?

I have a SQL string and it looks something like this:

SELECT field1, field2, field3
FROM dbo.BLAH_ABC_TABLE1
INNER JOIN dbo.FOO_BAR_TABLE2 on dbo.FOO_BAR_TABLE2.myfield = field1
INNER JOIN dbo.ABC_TABLE3 on dbo.ABC_TABLE3.myfield2 = field1
ORDER BY dbo.BLAH_ABC_TABLE1.myfield

Anywhere where there is "dbo.XXX_YYY_ZZZZ" I need to replace it with "dbo.ZZZZ". e.g.
      "dbo.AAA_BBB" gets changed to "dbo.BBB"
      "dbo.AAA_BBB_CCC_DDD" gets changed to "dbo.DDD"
      "dbo.TEST" remains unchanged.

So for example, the above string would be converted into

SELECT field1, field2, field3
FROM dbo.TABLE1
INNER JOIN dbo.TABLE2 on dbo.TABLE2.myfield = field1
INNER JOIN dbo.TABLE3 on dbo.TABLE3.myfield2 = field1
ORDER BY dbo.TABLE1.myfield
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros