RegEx : Remove line breaks if lookbehind shows a lowercase

微笑、不失礼 提交于 2019-12-09 22:58:59

问题


I'm doing a CTRL+H (Find & Replace) in Notepad++

I want to find all Line breaks followed by lowercase characters in order to replace them with a space character ; thereby removing unwanted break lines in my text.

Find : \r\n+(?![A-Z]|[0-9])

Replace : insert space character here

*Make sure you selected "Match case" and "Regular expression".

It works perfect.

Now, I'd like to do the same in Microsoft Office Word documents. Any clues?


回答1:


In Microsoft Word, do the following:

  1. On the Home tab, in the Editing group, click Replace to open the Find and Replace dialog box.

  2. Check the Use wildcards check box. If you don't see the Use wildcards check box, click More, and then select the check box.

  3. In the Find what: box, enter the following regular expression: ([a-z])^13

  4. In the Replace with: box, enter: \1 - thats: (backslash 1 SPACE) (don't forget the space!)

And that's it! Then click either the Replace button or the Replace All button.

Note: In MS Word, the ^13 character matches the paragraph mark at the end of each line.

Here's more information about Microsoft Word and Regular Expressions - http://office.microsoft.com/en-us/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx

Edit:

Oh, the above matches lowercase letter PRECEDING line break.

If you want to match line break FOLLOWED by lowercase letter, do the following:

  1. In the Find what: box, enter the following regular expression: ^13([a-z])

  2. In the Replace with: box, enter: \1 - thats: (SPACE backslash 1) (don't forget the space!)

Tested both ways and they both work in Microsoft Word 2010, however documentation says that regular expressions are supported in all versions 97 - 2013.

Good luck! :)



来源:https://stackoverflow.com/questions/21590316/regex-remove-line-breaks-if-lookbehind-shows-a-lowercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!