Find and Replace with Regex in Microsoft Word 2013

2020-02-27 04:12发布

问题:

I am editing an e-book document with a lot of unnecessary markup. I have a number of sections in the text with code similar to this:

<i>Some text here</i>

I am trying to run a regex find and replace that will find any phrase between the two i-tags, remove the i-tags, and apply a style to the text.

Here is what I'm using to search:

Find: (<i>)(*)(</i>)
Replace: \2

I'm also selecting Styles > i (for italic). This tells our conversion software to apply italics to the text. If I leave the i-tags, what ends up happening is ScribeNet's conversion process converts them to hex-values so that they show up as literal text in the e-book. Messy.

When I run this search, I get no results. I have "use wildcards" checked. What am I missing? According to Microsoft's help website, * is used to represent any number or type of characters, and individual strings are supposed to be enclosed in parentheses.

回答1:

To search for a character that's defined as a wildcard, place a backslash (\) before that character. The * itself matches any string of characters, so use the range quantifier to match (1 or more times)

Find: \<i\>(*{1,})\</i\>
Replace: \1


回答2:

Search for \<i\>(*{1,})\</i\> and replace with \1. Don't forget to check Use wildcard.

There is a reference table for Word's "regular expressions" here: http://office.microsoft.com/en-ca/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx

  • < and > are special characters that need to be escaped
  • * means any character
  • {1,} means one or more times