Regex to convert CamelCase identifiers to UPPER_CASE - regex

I have following lines
GetAuthServerList
GetAuthServerConfiguration
AddAuthServer
I have to convert them to
GET_AUTH_SERVER_LIST
GET_AUTH_SERVER_CONFIGURATION
and so on.
I tried to replace ([A-Z][a-z]+) with \1_ in sublime text editor, but it is replacing the last search also. How do I skip the last match of the line?
Can I simultaneously insert _ and make the lower case to uppercase in one replacement?

Find what : ([a-z])([A-Z])
Replace with: \1_\2
You have an option to convert selection to uppercase in sublime text.

I don't have sublime installed, but try this:
[a-z](?=[A-Z])
replace it with &_
or
replace ([a-z])(?=[A-Z]) with \1_
in vim it would be:
%s/\v[a-z]([A-Z])#=/&_/g

A little modification using negative lookahead should help
([A-Z][a-z]+)(?!$)

Related

Regex Transform or Text Replace in Text Editor

I am trying to do an advanced text search and replace in a text editor (I can use SublimeText or VSCode)
Input:
parameters['myParameter1']
parameters['myParameter2']
Expected output:
myParameter1
myParameter2
And I have hundreds of similar scenario in the file. So that's why I'm thinking of using regex to solve this.
Thanks
Hope this will help you out.
Regex demo
Regex search: parameters\['([^']+)'\]
1. parameters\[' this will match parameters[' Optinally if you have other keywords then parameters and which can be dynamic for that you can use [a-zA-Z]+ this will include all lower case and upper case.
2. ([^']+) this will match all except ', () will capture first match in $1.
3. '\] this will match ending ']
Replacement: $1
Note: If you are using gedit ubuntu you have to replace it with \1
VSCode can search all files in a directory, and it supports RegExp too!
Use ctrl+shift+f to search all files, hit the .* icon for RegExp.
A search expression such as parameters['(.*)'] replaced with $1 should work!
Check out the official guide for more info: VSCode Basic Editing

Notepad++ Remove text before characters but have 2 same characters on every line

Hi masters i need your help on Notepad++ RregExpp
i have text like this :
01:example#mail.com:test
need to convert like this :
example#mail.com:test
Thank you in advance if you help me.
Use expression ^... and replace it with empty string or better with \n like following (and remove the first two characters):
Here is a way to go:
Ctrl+H
Find what: ^[^:]+:(.+)
Replace with: $1
Replace all
Make sure to have checked Regular expresion but NOT . matches newline

How to lowercase selected text using a Replace RegEx in Notepad++

I'm looking for a way to lowercase selected BACKTICKED text using a regex in Notepad++
Here's an example string:
Select * FROM `Weird_TEXT` WHERE
And the desired output:
Select * FROM `weird_text` WHERE
I can find these strings (including the backticks) using the regex:
(?<=FROM )(.*)(?= WHERE)
`Weird_TEXT`
But I can't figure out how to replace the text as lowercase, I've tried using the following:
\1\L\2\L
\1\L\2\L\3
EDIT:
When I click Find Next in Notepad++, the backticks around the word Weird_TEXT are included in the selection. Could this be why the RegEx isn't working?
Just put this in the replace box:
\L$1

How to use RegEx to add "_" between two words with notepad++

I want to use Notepadd++ replace option with regular expression to accomplish this:
From: IntegrationName
To: Integration_Name
How can do this ?
My RegEx to search is: .[A-Z]
this finds: "oN"
But I don't know what to put in the replace box so it will only add "_" between the "o" and the "N"...
Another solution using lookaround assertions would be:
(?<=[a-z])(?=[A-Z])
and replace with
_
Note: The "Match case" option needs to be active, otherwise Notepad++ will find a match between every two letters.
This regex will find every position where a lowercase is on the left and an uppercase is on the right.
You can make use of capture groups. If I have to take your current attempt and edit it as little as possible, you would get:
(.)([A-Z])
This will store the match of . into $1 and the uppercase letter in $2, thus, you can use the following in the replace entry box:
$1_$2
I know you've accepted an answer, but when I ran it, I got From: _Integration_Name
Here's my idea;
(:\s)(.{1})([a-z]*)([A-Z]{1})
And use the following replace
$1$2$3_$4
I finaly did it like this:
Find: ([a-z])([A-Z])
Replace with: $1_$2

Sublime text find and replace with special characters

I suck at regular expressions and what to do a simple find and replace of '}' to '} /n' notepad++ can recongise what I'm after as it has the 3 options of normal find and replace, special chars and full regex. I however only ever used to option two. How can I enable special characters in my search using sublime text 2.
Cheers
Joe,
In sublime you can use find & replace. Drag the replace panel large enough and use cmd + enter to go to a new line.
Hit replace all:
And thats it your sorted chap
If you want to replace } within notepad++ with } \n you can use the following rules:
find: }
Replace with: } \n
Searchmethod: Extended (\n, \e...)
Press replace all