iadcialim24
iadcialim24

Reputation: 4015

Regex & Sublime: Replacestring

I have around 500 lines of this in my model:

var jobTitle: FieldInfoModel? = null

I want to make each line to be like this:

@Json(name = "job_title") var jobTitle: FieldInfoModel? = null

I am very noob in regex. Im planning to copy all the lines in Sublime and do the replacement magic there. Anyone can help me what to put in the Search and Replace fields?

Upvotes: 0

Views: 72

Answers (1)

revo
revo

Reputation: 48711

I can't think of a one-liner regex solution for working out the problem but can provide a two-step process in order to reach it:

Step 1

Find: var\s*(\w+)

Replace with: @Json(name = "\1") $0

Step 2

Find: (@Json\(name = "|(?!\A)\G)([a-z]+)([A-Z])

Replace with: \1\2_\L\3

See action in GIF

Notes:

\L Causes all subsequent characters to be output in lower case, until a \E is found.

\U Causes all subsequent characters to be output in upper case, until a \E is found.

Upvotes: 1

Related Questions