Regular Expresson for SQL keyword with spaces

You drag the column node in SQL Management studio so you have access to individual columns. You delete some field and keep other and want to pull data from the table.The proble is some field name contain spaces such as “First Name”, or “Local Address”. they are seperate only by ,

select first name, street address, city name, zip code from mytable

It would be painful to put brackets around every single keyword. You can use regular expression in SSMS or Visual studio or any other online utility to bring this into proper format.

I used the followring reqular expression in SSMS

Regular Expression: <[A-Za-z ]*
Replace Expression: []
< - start of word
[A-Za-z ] - Any english alphabet or a space. The space is important here

When the matching patter reach a comma, it will automatically truncate because commm (,) is not included in the matching patter
for replacement text type []. This will replace the existing match inside brackets [].

Previous logic

This logic was not that robust.

<[A-Za-z]*[ ]+[A-Za-z]*
< - start of word
[A-Za-z]* - Any valid character 1 or more time

If you want to put brackets aro

Advertisements
This entry was posted in Software Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s