Replace tilde in dictionary by headword
Hello everybody
I'm very new in scripting but this is what I want:
<ar><k>заглушать</k>
, заглушить (вн.) 1. (звук) deaden (smth.) , muffle (smth.) , smother (smth.) ; (более громким звуком) drown (smth.) ; шум ветра заглушил его слова the noise of the wind drowned his words; 2. (ослаблять какое-л. чувство, ощущение) deaden (smth.) ; ~ боль deaden pain; 3. (растения) choke (smth.) ; 4. (подавлять) stifle (smth.) ; ~ голос совести stifle the voice of conscience.</ar>
<ar><k>загляденье</k>
с. разг. lovely sight; feast for the eyes идиом. ; она просто ~! she`s simply lovely!</ar>
<ar><k>заглядывать</k>
, заглянуть 1. (смотреть) look; (незаметно) peep, peer; заглянуть кому-л. в лицо peer/look into smb.`s face; ~ в словарь look in a dictionary; 2. (бегло прочитывать) take* a look/glance (at), glance through; 3. ~ в душу человека seek* an insight into a person`s heart, try to penetrate a person`s innermost feelings; 4. разг. (заходить куда-л.) look in (at), drop in (at); ~ вперёд look ahead; ~ в будущее get* a glimpse of the future.</ar>
<ar><k>загораживать</k>
загоражив|ать - , загородить (вн.) 1. (обносить оградой) fence in (smth.) ; ~ двор забором enclose a yard, fence in a yard; 2. (преграждать) block (smth.) , obstruct (smth.) , bar (smth.) ; ~ кому-л. дорогу block smb.`s way; 3. (заслонять) shield (smth.) ; ~ кому-л. свет be* in smb.`s light; не ~айте мне свет would you mind keeping out of my light; ~аться, загородиться 4. fence one self off, shut* one self off; 5. (заслоняться) screen one self, shield one self.</ar>
I want replace tilde every time by its corresponding headword
some tildes have spaces from 2 sides this will take the full word between <ar><k> and </k>
and text from beginning to this sign " | " will replace tilde without space after : for example ~аться will become загораживаться
I tried something very simple and very weak but it is not working:
-----------------------------------------------------------------------------------------------------------------------------------
// Search the document for the string "first word in paragraph"
app.findGrepPreferences.findWhat = "<ar><k>.*?</k>";
var mySel = app.selection[1];
app.copy;
//Search the document for the string " ~ " and replace it by "the first word in paragraph".
app.findTextPreferences.findWhat = " ~ ";
app.changeTextPreferences.changeTo = app.findGrepPreferences.findWhat = app.paste;
app.activeDocument.changeText();
// Search the document for the string "any letters from beginning of the line until | symbol "
app.findGrepPreferences.findWhat = "^.*?|";
var mySel = app.selection[1];
app.copy;
app.findTextPreferences.findWhat = " ~";
app.changeTextPreferences.changeTo = app.findGrepPreferences.findWhat = app.paste;
app.activeDocument.changeText();
-----------------------------------------------------------------------------------------------------------------------------------
Can anyone help me how it will be the best script form can be used without mistakes in this script??
thanks a lot for all your answers
