Regularly removing special characters and spaces and then camel

I am trying to generate C # properties using regex from question names. I have over 100 and the task is likely to repeat itself, so it's worth the effort.

The lines to be converted:

Do you own your property?
How is it owned?
Relationship to other registered owner
Estimated value of Estate (joint)
Address Line 1
Are any of the children under 18 years old?
Are you interested in safeguarding your assets for your children/beneficiaries?

      

Expected Result:

public string DoYouOwnYourProperty { get; set;}
public string HowIsItOwned { get; set;}
public string RelationshipToOtherRegisteredOwner { get; set;}
public string EstimatedValueOfEstateJoint { get; set;}
public string AddressLine1 { get; set;}
public string AreAnyOfTheChildrenUnder18YearsOld { get; set;}
public string AreYouInterestedInSafeguardingYourAssetsForYourChildrenBeneficiaries { get; set;}

      

I followed and found flavors of regex questions where they removed special characters or might UpperCase in code , but not only do regex.

I started with this

([a-zA-z])( [a-zA-z])([a-zA-z])

      

Replace:

\1\U2\3

      

However, group 2 does not get the top and I am not sure how to add public string

and { get; set;}

for all, not for each group.

+3


source to share


2 answers


In Notepad ++:

Step 1: Remove punctuation

Replace the following pattern:

[^\w\s]

      

With an empty line.

Step 2: Remove spaces and write uppercase letters

Replace the following pattern:

[^\S\r\n]+(\d*\p{L}|\d+)

      

Wherein:



\U$1

      

Step 3: Add Property Syntax

Replace the following pattern:

^(\S+)$

      

Wherein:



public string $1 { get; set; }

      


For reference, here's what Notepad ++ uses to replace regex: Boost extended format syntax syntax

+1


source


You cannot work with regex101.com as its available engines do not support replacement tokens \U

and \L

. However Notepad ++ is fine.

First use this regex to match those spaces / punctuation and their next character:

[^[:alnum:]\n\r](\w)?

      

replace it with

\U$1

      



enter image description hereSecond , match the last line altogether:

^(?i)([a-z\d]+)$

      

and replace with:

public string $1 { get; set;}

      

enter image description here

+1


source







All Articles