Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: (solved) Need help with regular expressions in notepad++ find/replace  (Read 7700 times)

Moogie

  • Bay Watcher
    • View Profile

I'm modifying the language raws and I'm trying to do a mass find/replace in notepad++ but I really don't know what I'm doing with regular expressions. Could someone be so kind as to help me out and tell me what I need to use for both the Find and Replace fields?

Each line looks like this:

[T_WORD:APPLE:orange]

The pattern I'm searching for is this:

APPLE:orange]

...and I want to replace it with this:

APPLE:apple]

...so that the second word in lowercase is the same as the first word in uppercase. I've had some limited success with the Find field, using this expression:

:[A-Z].*\]

which highlights ":APPLE:orange]" but I don't understand how to do the replacement. I know I need to use parenthesis somehow, but my attempts at doing that failed hilariously. :D

Thank you for any help~
« Last Edit: May 15, 2012, 06:52:32 am by Moogie »
Logged
I once shot a bear in the eye with a bow on the first shot, cut it up, found another one, and shot it in the eye too. The collective pile of meat weighed more than my house.

nanomage

  • Bay Watcher
    • View Profile
Re: Need help with regular expressions in notepad++ find/replace
« Reply #1 on: May 14, 2012, 06:46:03 am »

you put things that you want to use in replace statement in parentheses, and then you refer to them as $1,$2 and so on, depending on the position.  Don't know how to make your editor convert string to uppercase though. Are you sure it's necessary? If it's indeed so, it might prove easier to user perl or powershell for that I think.
Logged

Moogie

  • Bay Watcher
    • View Profile
Re: Need help with regular expressions in notepad++ find/replace
« Reply #2 on: May 14, 2012, 07:19:15 am »

Thanks, I read about using parenthesis around the parts I want to use in the Replace field but it didn't work as expected... all it did is write the letter 'A' instead of copying the string it found. (I put the parenthesis around "[A-Z]", not just "A")

Regarding converting the string to lowercase, I just want to do that so that the words ingame aren't all written 'LIKE THIS'.

I also read that Notepad++ should support /U and /L for making uppercase and lowercase, but that didn't seem to work for me either.
« Last Edit: May 14, 2012, 07:20:55 am by Moogie »
Logged
I once shot a bear in the eye with a bow on the first shot, cut it up, found another one, and shot it in the eye too. The collective pile of meat weighed more than my house.

Moogie

  • Bay Watcher
    • View Profile
Re: Need help with regular expressions in notepad++ find/replace
« Reply #3 on: May 15, 2012, 06:18:23 am »

Edit: Aaaand seconds after I post this, I cracked it. I was missing an asterisk. Now Find works for words of all lengths, like so:

:([A-Z].[A-Z]*):([a-z].*) Problem solved! :)


I totally just simplified the whole thing, whilst also allowing the expression to pick up and replace words including symbols, regardless of where those symbols appear in the word. Now it's perfect. I'm posting this in the rare case that someone else comes looking for a similar solution. The final, bestest Find/Replace expressions for fully translating any language file into readable ingame English, using Notepad++ is:

Find
:([A-Z].*):(.*)

Replace
:(\1):(\L\1)]
« Last Edit: May 15, 2012, 06:30:10 am by Moogie »
Logged
I once shot a bear in the eye with a bow on the first shot, cut it up, found another one, and shot it in the eye too. The collective pile of meat weighed more than my house.

Intrinsic

  • Bay Watcher
    • View Profile

If you are just searching for APPLE:orange] and to replace it with APPLE:apple] why not just press ctrl+h and stick it in the corresponding fields? regex is totally overkill for something so simple.
Logged
Start Duelyst with a bonus 100gold, use referral code: Buttfungus
Enter during signup or ingame under Settings.

Hugo_The_Dwarf

  • Bay Watcher
  • Modding Mentor
    • View Profile
    • Regeneration: Forced Evolution

Well he isn't just looking for APPLE:orange, that was just and example, He wanted something that could convert an entire language file to English.

Less of course I'm wrong and he really did all that for one item :P
Logged

Moogie

  • Bay Watcher
    • View Profile

Well he isn't just looking for APPLE:orange, that was just and example, He wanted something that could convert an entire language file to English.

Less of course I'm wrong and he really did all that for one item :P

This, of course.

Don't worry, Intrinsic. Everybody has a "Brain switch = off" day. ;)
Logged
I once shot a bear in the eye with a bow on the first shot, cut it up, found another one, and shot it in the eye too. The collective pile of meat weighed more than my house.