0


Im using Jedit and regular expression to replace some text in several code from files.

There are a lot of similar start and ends like:

Something
Text Sample
Something Else

Or

Something
I dont know what else
Something Else

Then I search using:

Something
[^‰\r\n]*
Something Else

And I want to replace all lines with:

Something
<Tuv Lang="EN-US">**ORIGINAL TEXT**</Tuv><Tuv Lang="PT-BR"> </Tuv>
Something Else

So it will add some code in the beggining and at the end of the middle text line that is not always equal.

I have tried using:

Something
<Tuv Lang="EN-US">[^‰\r\n]*</Tuv><Tuv Lang="PT-BR"> </Tuv>
Something Else

But without success. Can somebody tell me how is the correct regular expression should I use?

Thanks in advance!

Matias

Alan Moore
  • 73,866
  • 12
  • 100
  • 156

2 Answers2

0

Try to modify your search to:

Something
([^‰\r\n]*)
Something Else

This should 'capture' what's inside the brackets and store it in a variable, $1.

Then, try this replace:

Something
<Tuv Lang="EN-US">$1</Tuv><Tuv Lang="PT-BR"> </Tuv>
Something Else

I can't say if this will work I jEdit or not since I don't have it through.

Jerry
  • 70,495
  • 13
  • 100
  • 144
0

Search:

Something(\s*)(.*?)(\s*)Something Else

Replace:

Something$1<Tuv Lang="EN-US">$2</Tuv><Tuv Lang="PT-BR"> </Tuv>$3Something Else

This captures the newline(s) as well as the wrapped text and puts it all back in the right place, meaning that whatever newline chars are present are preserved.

See live demo of regex matching sample input

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Note the [`?` non-greedy modifier](http://www.regular-expressions.info/repeat.html) which is important if two chunks are in a single file. – Ross Rogers Sep 24 '13 at 20:34
  • I have test it but it doesnt work. It is replaced but without words/text (where you add $2). Anyway thanks both of you for the answers! BTW I will take a look at the live demo page you send, it looks nice! – user2809038 Sep 25 '13 at 00:41
  • Try using `\1` instead of `$1` etc in the replacement text. There's no standard for back references - your tool might be the backslash variety – Bohemian Sep 25 '13 at 00:46