Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ahmadelmorshedy/7457f1c2270dca8c70a48574df99b4c7 to your computer and use it in GitHub Desktop.
Save ahmadelmorshedy/7457f1c2270dca8c70a48574df99b4c7 to your computer and use it in GitHub Desktop.
PLEASE DO IT CAREFULLY, SPECIAL CASES MAY OCCUR, SO BULK REPLACE IS NOT RECOMMENDED
find: (:)(((?!:).)*?)(\s*=>)
replace: ${2}:
explanation:
i. the brackets are used to create capture/matches groups, so that you can ommit the : (group 1) and the => (group 3)
and use only the key (group 2)
ii. ((?!:).)*? finds KEY text, it searches any text, expect it should not have : included, that's the role of (?!:) part,
the ? is used to mark a non-greedy search, if not marked, some text like :KEY1 => VAL1, :KEY2 => VAL2 will end up
as (:), (KEY1 => VAL1, :KEY2) and (=>) as the groups
iii. the replacement ${2}: takes the second group and appends : to it
references:
https://forum.sublimetext.com/t/search-with-regex-and-replace-with-found-text/26914/2
https://stackoverflow.com/questions/2503413/regular-expression-to-stop-at-first-match
https://www.regextester.com/15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment