Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the string or substring within nth occurrence in a line

I would like to find the third occurrence of string inside quotes in order to replace this string or part of this string. This is a typical line I have to deal with:

"/activities/absenceactivity/lang/#LANG_ID#/prop_dialog.php";"BA2_PD_SCR";"Opis dogodka";"Event description";"Descrição do Evento";"ÐÐ¿Ð¸Ñ Ð¿Ð¾Ð´ÑÑ";"";"č®vykio aprašymas";"Descripción del evento";"";

I know that "([^"]*)" shows every occurrence of text and quotes but I would like to get just the third one, in this example "Opis dogodka" in order to perform Search & Replace in Sublime Text.

Problem is to find the third occurrence of string within the quotes, replace it entirely or just partially and make sure that the Regex provides also a solution for an empty

""

strings.

Thank you.

like image 980
andrej Avatar asked Nov 22 '25 16:11

andrej


1 Answers

I'm sure there are ways to simplify this further, but if you're ok with brute force:

Sublime command:

 Find: "[^"]*";"[^"]*";"([^"]*)".*
 Replace: $1

NP++:

 Find what: "([^"]*)";"([^"]*)";"([^"]*)".*
 Replace with: $3

sed:

 sed 's/"\([^"]*\)";"\([^"]*\)";"\([^"]*\)".*/\3/'
like image 156
CoreyJJohnson Avatar answered Nov 24 '25 08:11

CoreyJJohnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!