Notepad++ and regex: how to UPPERCASE specific part of a string / find / replace

zen or the art of regex picture zen or the art of regex · Aug 20, 2014 · Viewed 14k times · Source

i've been trying for some time now to get this working, but i can't find a solution to this task myself - ok, i'm very new to regex-use but quite interested to learn, hope anybody has some brainfood for me...

my text-string is like this - without the numbers...

Word1 Word2 word3 (some words in brackets)
Word1 (some words in brackets)
word1, Word2 (some words in brackets)

means: an indefinite number of words (sometimes just one, maybe 2 to 4, sometimes separated by commas) followed by a string in round brackets (the value in the brackets should not change)

what i'm looking for is two different regexes - to use with FIND and REPLACE in notepad++
1. only uppercasing of all the words before the brackets
2. like no.1 + adding html-tags)

should look like: 1:

WORD1 WORD2 WORD3 (some words in brackets)
WORD1 (some words in brackets)
WORD1, WORD2 (some words in brackets)

and 2:

EDIT: 2nd html-tag was at the wrong position, now right!

%htmltag%WORD1 WORD2 WORD3%/htmltag% (some words in brackets)
%htmltag%WORD1%/htmltag% (some words in brackets)
%htmltag%WORD1, WORD2%/htmltag% (some words in brackets)

hope somebody could help me - thax a lot beforhand!

Answer

Keith Nicholas picture Keith Nicholas · Aug 21, 2014

For part 1 you can use

Find:  ^(.*?)(?=\()
Replace \U\1

Make sure regex is selected

for part 2

Find: ^(.*?)(\(.*?\))
Replace:%htmltag%\1%/htmltag%\2

which takes

WORD1 WORD2 WORD3 (some words in brackets)
WORD1 (some words in brackets)
WORD1, WORD2 (some words in brackets)

and converts it to

%htmltag%WORD1 WORD2 WORD3 %/htmltag%(some words in brackets)
%htmltag%WORD1 %/htmltag%(some words in brackets)
%htmltag%WORD1, WORD2 %/htmltag%(some words in brackets)