I have a word document which I pass to a function that super script everything between two "£"'s. The problem is that if I don't have enabled English setting on my computer there will display a error (in swedish) complaining about the matching. I guess it has something to do with this particular line doc.Find.Text = "£([AZ]{1,5})£";
since the document also contains letter å,ä and ö. However I can't get it to work no matter what I try, I'm really stuck. I'm not an Interop expert so if anyone could help me out I would appreciate it a lot!
public void SuperScript(Word.Range doc)
{
doc.Find.Replacement.Font.Superscript = 1;
doc.Find.MatchWildcards = true;
doc.Find.Text = "£([0-9]{1,5})£";
doc.Find.Replacement.Text = @"\1";
doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
doc.Find.Text = "£([A-Z]{1,5})£";
doc.Find.Replacement.Text = @"\1";
doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
doc.Find.Text = "£([a-z]{1,5})£";
doc.Find.Replacement.Text = @"\1";
doc.Find.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Word.WdReplace.wdReplaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
我只是在猜测......希望这是你的答案......你可以做这样的事情"£(\\w[^0-9]{1,5})£"
或"£(\\D{1,5})£
不包括数字。如果您不关心返回的字符类型,则可以执行"£(.{1,5})£"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.