RegEx : Remove line breaks if lookbehind shows a lowercase - regex

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?

In Microsoft Word, do the following:
On the Home tab, in the Editing group, click Replace to open the Find and Replace dialog box.
Check the Use wildcards check box. If you don't see the Use wildcards check box, click More, and then select the check box.
In the Find what: box, enter the following regular expression: ([a-z])^13
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:
In the Find what: box, enter the following regular expression: ^13([a-z])
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! :)

in vscode tap on find press the keys ctrl/enter for second line then type (?=[a-z]) and in the replace add a space

Related

How to replace uppercase letters by their lowercase counterparts?

I have a big text document in which suspension points are followed by a capital letter. It should be lowercase. Now I figured to use this expression in search & replace: …\ [:upper:] which works fine to find the parts I want to replace, but when I try to do that with …\ [:lower:] I pastes literally that expression rather than the same letter but lowercase. What am I doing wrong? Thanks!
You can't use [:lower:] this way, because it's only a pattern to match the search text; it doesn't affect or transform the matched text part.
To solve your issue:
Put the search pattern in round brackets. This makes the current matched text available for the replacement pattern.
Reference the current match in the replacement pattern using $1 (assuming there's only one pair of round brackets in your search pattern);
Tell LO Writer to use lower-case characters when replacing.
Step by step (the following example will simply replace every upper-case letter by its lower-case counterpart):
Open find/replace (CTRL+H or Menu Edit -> Find/Replace...)
As search pattern, enter ([:upper:])
Make sure that "Regular expressions" is selected in "Other Options";
As replace pattern, enter $1 (this simply uses the complete current match as replacement);
Still with cursor in the "Replace" input box, hit the Format... button; this will open the "Replace with Formatting" window.
In the "Replace with Formatting" window, select "Font effects", and from "Effects" -> "Case", select "lowercase". Hit OK.
Execute the Find/Replace.

RegEx in Notepad++ to find and replace strings

I'm trying to find and replace strings using RegEx on Notepad++, but cannot identify the right expression to do it:
Here is the data:
TRAIN-II
TRAIN
TRAIN-I
AIRPLANE-II
AIRPLANE
AIRPLANE-I
SHIP-II
SHIP
SHIP-I
Well, I want to keep only the string which has "-II" as suffix. In simpler words, I want to retain only:
TRAIN-II
AIRPLANE-II
SHIP-II
Can anyone please help?
Ctrl+H
Find what: ^.*(?<!-II)(?:\R|\Z)
Replace with: LEAVE EMPTY
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
^ # beginning of line
.* # 0 or more any character but newline
(?<!-II) # negative lookbehind, make sure we haven't -II before the following
(?:\R|\Z) # non capture group, any kind of linebreak (i.e. \r, \n, \r\n) or end of file
Screenshot (before):
Screenshot (after):
Use a regex to mark the lines, then remove unmarked lines.
Open the search window and then the "Mark" tab.
Enter -II$ into the "Find what" box. Select "Regular expressions". Select "Match case" if the "II" must be in upper case. Select "Bookmark line". Click on "Mark all". Expect to see the wanted lines marked with a blue circle. Use menu => Search => Bookmark => Remove unmarked lines.

Finding lines starting with lowercase letter

I have a long text which has some lines are seperated. How can I find the lines starting with lowercase letters?
Make sure both the "regular expressions" and "match case" options are checked and try this:
\r\n[a-z]
This will search for a carrriage return (new line) followed by a lowercase letter.
Try
ctrl + h
Then make sure that regular expression is checked and use
^[a-z]
If you hold ctrl + h and you type ^[a-z], it should work, make sure the matches newline option is selected is selected and the regular expression option.
Notepad++ regex helper

Notepad++ Search and Replace: delete all after "/" in each row

I have a plain text file with content like this:
prežrať/RN
prežrieť/Z
prežrúc/zZ
prežuť/c
...
Q: How can I remove all strings after / symbol in every row in Notepad++?
Desired output:
prežrať
prežrieť
prežrúc
prežuť
...
I am doing this with Find-and-Replace for every different string after /, but there are too many combinations.
Search for: /.*, replace with nothing.
The character / matches just /. ., however, matches any character except newlines, so .* will match a sequence of characters up until the first newline. You can find a demonstration here: http://regex101.com/r/kT0uE3.
If you want to remove characters only after the last on the line /, you should use the regex /[^/]*$. You can find an explanation and demonstration here: https://regex101.com/r/sZ6kP7/74.
In regular expression mode
Find:
/.*
Replace:
(empty)
Set find and replace to regular expression mode.
Find string: /.*
Replace String: (empty string)
Notepad++ find and replace is by default line ended (it won't go over multiple lines)
Using find and replace:
Hit CTRL-H to open the Replace dialogue box
enter /.* into "Find what"
leave "Replace with" empty
Select "Regular expression" (and .matches newline if it is single line)
Click on Replace
Here we go... You are done.

Replace leading spaces with Notepad++

I'd like to use Notepad++ to replace all leading spaces on a line with a like number of given characters. So for instance, I want to change:
zero
one
two
three
into:
zero
#one
##two
###three
I haven't been successful at getting this working. I did find Regex to replace html whitespace and leading whitespace in notepad++, but wasn't able to get the result I wanted.
Is this possible with Notepad++? I'd rather not have to write code to do this...
As Tim's answer indicates, this can't be done in a single search/replace, however here is how you can accomplish the same task fairly quickly using multiple replacements:
Find: ^( *)[ ]
Replace with: \1#
Now just spam the "Replace All" button until it indicates that there were no matches to replace. This will replace a single space at the beginning of each line on each click, so it will require the same number of clicks as your most-indented line.
Make sure "Regular expression" is selected as the search mode.
You would need variable-length lookbehind assertions to do this in a single regex, and Notepad++ doesn't support these.
For the record, in EditPadPro you can search for (?<=^ *)\s and replace with #.