224

I wrote a regular expression in hope that I will be able to replace every match (that is just one char) to upper case char. I am using EditPad Pro (however I am willing to use any other tool that would allow me to do this, as long as it is free to try, since I only need to do this once).

Background: I have a very long text file used by a case sensitive application, and some words start with lower case instead of upper case char, thus crashing the application. This would take very long to do by hand, and it would be quite complicated to do without regular expressions because the occurrence of the (evil) lower case char is very specific.

I have written the select regular expression and now I can use it with a backreference ($1 works just fine) however I can't make it replace with upper case char. I thought something like \u$1 would work, however it doesn't in EditPad Pro.

If no free tool allows me to do this, I guess the alternative would be to just do it in C# however I am in a bit of a hurry and not near a compiler, so I'd have to download the express edition first, so ... It would be preferable to find a tool that supports such a feature!

Thank you!

1
  • 3
    Is this question more suited to Superuser? Jul 24, 2012 at 20:36

7 Answers 7

383

TextPad will allow you to perform this operation.

example:

test this sentence

Find what: \([^ ]*\) \(.*\) Replace with: \U\1\E \2

the \U will cause all following chars to be upper

the \E will turn off the \U

the result will be:

TEST this sentence
17
  • 17
    Is there a way to perform this operation in .NET Regex (without using ToUpper)? Oct 27, 2011 at 10:52
  • 42
    Works in notepad++ as well.
    – Shawn
    Sep 6, 2013 at 15:15
  • 50
    \U$1\E in Sublime Text
    – Qwerty
    May 28, 2014 at 15:31
  • 7
    In Notepad++ find should be (.*) and replace should be \U$1 Jun 26, 2015 at 20:38
  • 12
    Works in PHPStorm too. I had the opposite requirement though. I had to replace all uppercase attribute values (from probably '90s HTML) to lower case. Using \L$1\E worked.
    – Ejaz
    Feb 7, 2016 at 14:27
39

I know this thread is about EditPad Pro, but I came here because I had the same need with a javascript regexp.

For the people who are here needing the same tip, you can use a function or lambda as the replace argument.

I use the function below to convert css names with - to the javascript equivalent, for example, "border-top" will be transformed into "borderTop":

    s = s.replace(/\-[a-z]/g, x => x[1].toUpperCase());
0
32

EditPad Pro and PowerGREP have a unique feature that allows you to change the case of the backreference. \U1 inserts the first backreference in uppercase, \L1 in lowercase and \F1 with the first character in uppercase and the remainder in lowercase. Finally, \I1 inserts it with the first letter of each word capitalized, and the other letters in lowercase.

Source: Goyvaerts, Jan (2006). Regular Expressions: The Complete Tutorial. Lulu.com. p. 35. ISBN 1411677609. Google Books. Retrieved on June 25, 2010.

0
10

Just an another ussage example for Notepad++ (regular expression search mode)

Find: (g|c|u|d)(et|reate|pdate|elete)_(.)([^\s (]+)
Replace: \U\1\E$2\U\3\E$4

Example:

get_user -> GetUser
create_user -> CreateUser
update_user -> UpdateUser
delete_user -> DeleteUser
7

You can also capitalize the first letter of the match using \I1 and \I2 etc instead of $1 and $2.

6

You can do this in jEdit, by using the "Return value of a BeanShell snippet" option in jEdit's find and replace dialog. Just search for " [a-z]" and replace it by " _0.toUpperCase()" (without quotes)

1
  • 1
    Your response is not really related to the initial question, but I found it while googling and was exactly what I was looking for. Awesome, thanks! Apr 4, 2012 at 21:41
0

For javascript users (i fell here coming from javascript) check this answer https://stackoverflow.com/a/73776269/7668448

Examples and reference

API

replace(
    regex,
    (matched, capture1, capture2, /*...,*/ capture_n, index, input_str) => transformed(/*...*/)
)
replace(
    regex: Regex,
    transformer: (matched: string, capture1: string, capture2: string, /*...,*/ capture_n: string, index: number, input_str: string) => string
) => string

Check the answer for the examples. Converting swc command args to camel case js equiv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.