Вопрос


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

Это было полезно?

Решение

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top