We help IT Professionals succeed at work.
Get Started

Regular Expression to modify a T-SQL query to return formatted dates. (Search and Replace REGEX)

megnin asked
Last Modified: 2015-04-16
I need a Regular Expression to reconstruct a T-SQL query with a bunch of date columns.

With query items like this:

The result should look like this:
      ,CONVERT(Varchar,[ObtainedGADataSheet],101) AS 'ObtainedGADataSheet'
      ,CONVERT(Varchar,[C_ObtainedGADataSheet],101) AS 'C_ObtainedGADataSheet'
      ,CONVERT(Varchar,[ReceivedJobDesc],101) AS 'ReceivedJobDesc'
      ,CONVERT(Varchar,[C_ReceivedJobDesc],101) AS 'C_ReceivedJobDesc'

The text editor I'm using to accomplish this is called "EditPad Pro 7" by "Just Great Software Co. Ltd." and supports Regex search and replaces.

I'm tried this in the Search: field:

And this in the Replace: field:
,CONVERT(Varchar,$&,101) AS '\0'

And I get this result:
      ,CONVERT(Varchar,,[ObtainedGADataSheet],101) AS ',[ObtainedGADataSheet]'
      ,CONVERT(Varchar,,[C_ObtainedGADataSheet],101) AS ',[C_ObtainedGADataSheet]'
      ,CONVERT(Varchar,,[ReceivedJobDesc],101) AS ',[ReceivedJobDesc]'
      ,CONVERT(Varchar,,[C_ReceivedJobDesc],101) AS ',[C_ReceivedJobDesc]'

There are two extra commas in this result.  Each extra is before a "[" character.   I see where it's coming from, but I don't know how to fix it.  Note that the brackets should be removed from the field name after "AS."

Thanks a bunch.
*Oh, I don't want a Python or C# solution, I'll be continuing to use my text editor's search and replace feature.
A reference to it's syntax can be found here, but it's pretty standard:
Watch Question
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE