0

I have a document in word. My paragraphs like:

asdfasdfasdf
abcYear052014
asdfasdfasdf
acbYear122013

I want delete line xxxYearyyyy so in notepad++ I put

.*[0-9]201[0-9]$

and replace with blank. So it delete the line which contain the result. But when I try in microsoft office 2013, it can't find anything despite of checking in 'use wildcard'.

Because my word file have a bold text so I must do in office. I think microsoft office isn't good at regex find :(

Any idea or solution?

Thanks for helping me.

Regard

3 Answers 3

2

MS Office does not support regular expression just as the source code editor like Notepad++.

You can try this, it does not fully work though:

<*201[0-9]>

Here is the MS help that discusses wild cards and regular expressions in MS Office.

https://support.office.com/en-ca/article/Find-and-replace-text-by-using-regular-expressions-Advanced-eeaa03b0-e9f3-4921-b1e8-85b0ad1c427f

1

The MS Word regex seriously lacks functionality. If you absolutely need to stay in word (and can't find another editor that both has good regex support and retains MS Word markup), I found a possible workaround for you using the word regex:

1) Prefix every line with a character that you know does not appear in your text. Say "#". You would get:

#asdfasdfasdf
#abcYear052014
#asdfasdfasdf
#acbYear122013

2) Now do a "regex" search and replace with the following regex, which will find line 2 and 4 in this list:

#[!#]@[0-9]201[0-9]

(Read: everything that starts with "#", then has one or more characters (@) that are not "#", then has a digit, then 201 and then a digit again.)

3) AFter your search/replace, simply search/replace again and replace all the # with nothing.

You could probably also work with a VisualBasic macro for word, a quick Google shows that VB does have regex. Another Google shows that someone over at Stack Overflow already did something like this, apparently: https://stackoverflow.com/questions/6128880/vb-script-to-find-and-replace-text-in-word-document

Another option would be to write a small script, like an AHK or AU3 script, that simulates keystrokes that do: 1. press down, 2. press home - shift+end - ctrl+c (copy line), 3. grab the line from the clipboard and test it against your regex, 4. press delete if line fits regex. I am not 100% sure that above would work with all exotic possibilities for MS Word markup, but if it's just bold lines it should work.

0

I have figured out.

It can replace the whole paragraph or line.

For my example:

abcd abcd xxx1234 efgh asdf

So, i check "use a wildcard" box in search office.

In find box:

^13*xxx[0-9]{4,}*^13

In replace box:

^p

(to delete the line or paragraph) or

^p(something you want to replace)^p

So

^13 enter to new line (it only use in find box when use wildcard not replace - if you need you must use ^p) ^p enter to new line (it can be use both find and replace in both use wild card or normal) * any character xxx[0-9]{4,} xxx and number from 0-9 and must have 4 digit above

Hope it help

Thank to two guys above

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .