Regular expression for finding non-breaking string names in code and then breaking them up for SQL q
- by Rob Segal
I am trying to devlop a regex for finding camel case strings in several code files I am working with so I can break them up into separate words for use in a SQL query. I have strings of the form...
EmailAddress
FirstName
MyNameIs
And I want them like this...
Email Address
First Name
My Name Is
An example SQL query which I currently have is...
select FirstName, MyNameIs from MyTables
I need the queries in the form...
select FirstName as 'First Name', MyNameIs as 'My Name Is' from MyTables
Any time a new capital letter appears that should be a new grouping which I can pick out of the matched string. I currently have the following regex...
([A-Z][a-z]+)+
Which does match the cases I have shown above but when I want to perform a replace I need to define groups. Currently I have tried...
(([A-Z])([a-z]+))+
Which sort of works. It will pick out "Address" as the first grouping from "EmailAddress" as opposed to "Email" which is what I was expecting. No doubt there is something I'm misunderstanding here so any help is greatly appreciated.