vba - MS word find and replace: Change how to replace based on captured values in Find's RegEx -


i working on bilingual documents (arabic-english), 2 languages have different directions (rtl , ltr respectively) makes working bit more challenging.

i writing macro change numbers of form (x.x) (x,x), change in comma.

now here problem, 2 numbers switched when replace, example: x.y becomes y,x.

after debugging turned out (.) in first form arabic character , when replaced (,) english 1 causing change in order.

so want following, don't know how translate vba:

1- match expression ([0-9]{1, }).([0-9]{1, }) 'two numbers dot in between  2- if dot in between english, replace follows \1,\2  'no change   3- else if arabic, replace follows \2,\1 

thanks help

edit
here current version of macro, recorded macro. added if else statement.

sub fixcomma() ' ' fixcomma macro ' '    if (selection.start <> selection.end)     selection.find.clearformatting     selection.find.replacement.clearformatting     selection.find.replacement.languageid = wdenglishus     selection.find         .text = "([0-9]).([0-9])"         .replacement.text = "\1,\2"         .forward = true         .wrap = wdfindstop         .format = true         .matchcase = false         .matchwholeword = false         .matchkashida = false         .matchdiacritics = false         .matchalefhamza = false         .matchcontrol = false         .matchbyte = false         .matchallwordforms = false         .matchsoundslike = false         .matchwildcards = true     end      selection.find.execute replace:=wdreplaceall      else       msgbox "nothing selected, macro terminated"     end if end sub 

edit 2
maybe taking wrong approach here , should go through paragraphs myself , check match regex instead of using find , replace ?

edit 3
maybe using wrong tool here , vba can't me ? if there else can use ? maybe c# add in example.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -