17

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!

2 Answers2

20

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)
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • Keith, this is great! You are my hero ;-) Any ideas for part2 as well? – zen or the art of regex Aug 20 '14 at 22:13
  • sorry to bother you again...this was close, but i editedt my question meanwhile- had the 2nd html-tag at the wrong position: i only want the UPPERCASED WORDS from before between tags (see above) - or even, if you know a solution for that too: SOME UPPERCASED WORDS IN A ROW followed by other words...-different for each line- and only the UPPERCASED should be set between tags, if possible?? – zen or the art of regex Aug 20 '14 at 22:26
  • just a sec...I'll do that – Keith Nicholas Aug 20 '14 at 22:31
  • there you go, just does the html tags for the words at the beginning – Keith Nicholas Aug 20 '14 at 22:32
  • part1 works perfectly, THANX! as for part2: do i interprete the find-regex correctly: we are searching for a string until the round bracket i.e. /1 followed by a second string /2 - then you try to reuse those two with the tags...should work, but somehow doesn't, hm?? – zen or the art of regex Aug 20 '14 at 22:41
  • maybe also an extra search for SOME UPPERCASE WORDS in a line...that could be captured, reused and altered would be cool - but how? – zen or the art of regex Aug 20 '14 at 22:47
  • not sure what the problem is? in notepad I take your example text and convert it fine, will show in my answer – Keith Nicholas Aug 20 '14 at 22:57
  • yeah, now it works for me as well - don't know what it was before...GREAT! THANX AGAIN! – zen or the art of regex Aug 20 '14 at 23:35
  • If you're looking to do the opposite, substitute \U with \L. For example, searching for `([A-Z])([A-Z]*)` and replacing with `\U\1\L\2' will convert the word to lower case apart from the first letter. – Aaron Mason Sep 01 '16 at 00:10
9

Scenario 1: generate uppercase for matches on Notepad++

You can use a regex like this:

\(.*?\)|(\w+)

Working demo

Then on your Find/Replace dialog you can put \U\1 on Replace with. So, if you go over Find Next you can replace the string to generate the uppercase output.

enter image description here

Scenario 2: concatenate tags on each line

You can use this regex:

(.+?)\[

Working demo

enter image description here

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123