Reputation: 4015
I have a long list (about 100k lines) of strings in my file like this:
job_title <- map["job_title"]
....
I want to do some replacement to make it like this:
jobTitle <- map["job_title"]
so I just replace _t
to T
, but I want the left side only.
Upvotes: 1
Views: 282
Reputation: 626927
If you replace _t
with T
, you will replace all occurrences of _t
with T
regardless of the context.
What you may try is to match all "..."
substrings and skip them, and then match any letter after _
and convert it to uppercase. How you match "..."
substrings depends on whether escaped entities may appear in your text or not.
If there can be no escaped quotes,
Search: "[^"]*"(*SKIP)(?!)|_([A-Za-z])
Replace: \u$1
If there can be escaped quotes:
Search: "[^"\\]*(?:\\.[^"\\]*)*"(*SKIP)(?!)|_([A-Za-z])
Replace: \u$1
Details:
"[^"\\]*(?:\\.[^"\\]*)*"(*SKIP)(?!)
- a "..."
substring (it matches "
, then any 0+ chars other than "
and \
and then 0+ sequences of any escaped char (\\.
) followed with any 0+ chars other than "
and \
, and then "
) that is matched and then omitted from the match, and the next match is searched for after the end of the current match (due to (*SKIP)(?!)
)|
- or_
- a _
char([A-Za-z])
- Capturing group 1: any ASCII letterThe \u
operator in the replacement makes the first char after it uppercase. $1
stands for the letter captured with ([a-zA-Z])
.
Upvotes: 2
Reputation: 26
With the following regex you match just the first _t
(?<=^job)_(\w)
so you could replace that with T.
See https://regex101.com/r/VcpAzt/1
Upvotes: 0
Reputation: 140
There is no need for regex in your case (press Ctr+H and replace all)
Replace
job_title <
with:
jobTitle <
Upvotes: 0