Regular expression for finding non-breaking string names in code and then breaking them up for SQL q
Posted
by Rob Segal
on Stack Overflow
See other posts from Stack Overflow
or by Rob Segal
Published on 2010-01-29T17:21:28Z
Indexed on
2010/03/28
0:03 UTC
Read the original article
Hit count: 303
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.
© Stack Overflow or respective owner