Dear list members,

I need to write a macro that tries to match a series of regexs against some
text I've selected and then replace it with a replacement string that
contains captured groups.

I've tried the following (borrowed and modified from some on-line code) but
it doesn't recognise $0,$1,$2,$3 as captured groups and just prints them
out as literals.
This is what I've tried:
---------------------------
Sub Stem1P()
Dim oDoc,oText,oVC,oStart,oEnd,oFind,FandR
oDoc = ThisComponent : oText = oDoc.Text
oVC = oDoc.CurrentController.getViewCursor


aFind = Array(
"([^aāiīuūṛṝḷḹeo[:space:]])(a)([^aāiīuūṛṝḷḹeo]h{0,1})[:space:]{0,1}",_
"([^aāiīuūṛṝḷḹeo[:space:]]*)(i)([^aāiīuūṛṝḷḹeo]h{0,1})[:space:]{0,1}",_
"([^aāiīuūṛṝḷḹeo[:space:]])(u)([^aāiīuūṛṝḷḹeo]h{0,1})[:space:]{0,1}",_
"([^aāiīuūṛṝḷḹeo[:space:]]*)(ṛ)([^aāiīuūṛṝḷḹeo]h{0,1})[:space:]{0,1}",_
"([^aāiīuūṛṝḷḹeo[:space:]]*)(ḷ)([^aāiīuūṛṝḷḹeo]h{0,1})[:space:]{0,1}")




aReplace = Array ( "$0 1P = $1[guṇa $2$3]->$1[$2$3]->$1a$3 + a->$1a$3a",_
"$0 1P = $1[guṇa $2$3]->$1[a+$2$3]->$1e$3 + a->$1e$3a",_
"$0 1P = $1[guṇa $2$3]->$1[a+$2$3]->$1o$3 + a->$1o$3a",_
"$0 1P = $1[guṇa $2$3]->$1[a+$2$3]->$1ar$3 + a->$1ar$3a",_
"$0 1P = $1[guṇa $2$3]->$1[a+$2$3]->$1al$3 + a->$1al$3a")


aRayCount = 0
While aRayCount <= uBound(aFind)
oStart = oText.createTextCursorByRange(oVC.Start)
oEnd = oText.createTextCursorByRange(oVC.End)
FandR = oDoc.createReplaceDescriptor
With FandR
.SearchString = aFind(aRayCount)
.ReplaceString = aReplace(aRayCount)
.searchCaseSensitive = true
.SearchWords = false
.SearchRegularExpression = true
End With
Do
oFind = oDoc.FindNext(oStart.End,FandR)
If isNull(oFind) then Exit Do
If oText.compareRegionEnds(oFind,oEnd) < 0 then Exit Do
oFind.setString(FandR.ReplaceString)
oFind = oDoc.FindNext(oFind.End,FandR)
Loop

aRayCount = aRayCount + 1
Wend
End Sub
--------------------
When I select the text   budh    and then run the macro it doesn't
recognize $0,$1,$2,$3 as captured groups but prints:

$0 1P = $1[guṇa $2$3]->$1[a+$2$3]->$1o$3 + a->$1o$3a
instead of what I want which is :

budh 1P = b[guṇa udh]->b[a+udh]->bedh + a -> budha

Thanks,
Harry Spier

Reply via email to