Uppercase after every character in NP++ - regex

I want to turn every letter after : to uppercase on every single line.
For example from:
nerd:class:ace
make:milk
lake:cake
to
nerd:Class:Ace
make:Milk
lake:Cake

Open Replace menu with Ctrl+h.
Ensure the Regular expression checkbox is ticked.
Enter :([a-z]) in the Find what : field (Alt+f). This matches and captures any letter following a :.
Enter :\U$1 in the Replace with : field (Alt+l). \U uppercases the captured letter in the matched group $1.
Press Alt+a to Replace All.

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.

Replace full stop between letters with hypen in sentance

Somehow some text pages I've been given seem to have a full stop where a hyphen should be.
For example, "Then it happened.first one foot.then the other.". As you can see there is a full-stop where a hyphen should be.
I figured out the Regex to 'find' ([a-z][.][a-z]) all the occurences but can't figure out the 'replace'.
When I tried, [ - ], [-], [a-z][-][a-z], [a-z][ - ][a-z] and [a-z][ ][-][ ][a-z] it removes the last letter of the the precceding word and the first letter of the following one.
I'm using a text editor (TextPad).
How do I solve this?
Consider [.](?=[a-z]):
It does avoid abbreviations assuming they're only uppercase.
It does not handle "Then it happened.Winnie the Pooh looked up." (The word after the hyphen is a proper noun.)
It also does not handle "Then it happened.G.W. Bush looked up." (The word after the hyphen is an abbreviation.)
To handle those cases, consider (?<![A-Z])[.](?!\s|$):
It says that the letter prior to the . should not be uppercase.
It also says that there shouldn't be spaces or end-of-lines after it.
You can perform the replace with just " - ", since the regular expression only consumes the period. (The context is matched using lookarounds.)
See the demo.
I don't have TextPad and cannot test my answer. From what I read, TextPad should support capture groups either via \1 or $1. Try one of the following
Search ([a-z])\.([a-z]) and replace with \1 - \2
or
Search ([a-z])\.([a-z]) and replace with $1 - $2
or
Search \([a-z]\)\.\([a-z]\) and replace with \1 - \2.
or
Search \([a-z]\)\.\([a-z]\) and replace with $1 - $2.
You can try like this
var string = "Then it happened.first one foot.then the other.";
var result = string.replace(/[.]/g,'-');

How to replace specific character one time

I want to replace character - using regular expression in my text so it would work like this:
Original text: abcd-efg-hijk-lmno
Text after replacing: abcd-efg-hijk/lmno
As you can see I want to replace character - starting from the end just one time with character /.
Thanks in advance for any tips
Find what: -([^-]*)$
Replace with: /$1
Search Mode: Regular Expression
Explanation:
- : a dash
([^-]*$) : text with no dash,
zero or more times,
to the end of the line,
put in the $1 variable
/$1 : literal "/", contents of $1
Good resource: http://www.grymoire.com/Unix/Regular.html
To replace characters in Notepad++, you can open the Replace window using Ctrl+H, or under the "Search" menu. Once open, enter the following regular expression:
(.{4}-.{3}-.{4})(-)(.{4})
This will find:
a group of four characters (the "." being any character, the "{4}" being the quantity),
a dash,
a group of three characters,
another dash,
a group of four characters,
again another dash,
then a group of four characters.
The parentheses group this search into captured groups, which we will use for the replacement part. See https://www.regular-expressions.info/brackets.html for more info.
If you want to restrict the search to lowercase letters as in your example, you would replace the "." with "[a-z]", or for upper and lower "[a-z,A-Z]".
Now for the replacement. The groups from earlier are referenced by the dollar sign then the number, e.g. $1 would be the first. So we will replace the characters found with the first group ($1), disregard the second group containing the dash and insert the "/" instead, then include the third group ($3):
$1/$3
The settings in the replace window need to have "Regular expression" and "Wrap around" checked, and ". matches newline" unchecked.
You can then click Replace all to replace all occurrences, or go through using Replace individually.
Since the beginning and end of line characters are not included, you can find multiple occurrences of this pattern on a single line.
Note: This answer follows the same procedure as Toto's, however uses a different regular expression.
Ctrl+H
Find what: ^(.+)-([^-]+)$
Replace with: $1/$2
check Wrap around
check Regular expression
DO NOT CHECK . matches newline
Replace all
Explanation:
^ : begining of line
(.+) : 1 or more any character, catch in group 1
- : a dash
([^-]+) : 1 or more any character but dash, catch in group 2
$ : end of line

Need to insert a tab in between every instance of a lowercase letter immediately followed by an uppercase letter

I am using TextPad 6 find and replace feature using regular expressions.
In the document I need to insert a tab in between every instance where a lowercase letter is followed by an uppercase letter that has no space between them.
But I cannot find the right regex combination to make this simple task work.
Example:
I want to find:
fooBar
replace with
foo [tab] Bar
This will result being a delimited file.
I have used
FIND:[a-z][A-Z]
REPLACE: &\t
RESULT: fooB ar
OR
FIND:[a-z][A-Z]
REPLACE:\t&
RESULT: fo oBar
OR
FIND:[a-z][A-Z]
REPLACE:&\t&
RESULT: fo oBar
Any ideas?
Use capturing groups:
FIND:([a-z])([A-Z])
REPLACE:\1\t\2
Like raina77ow said you need to capture the regex matched groups. This can be done by adding parenthesis.
I think this should do it.
Find:([a-z]+)([A-Za-z]+)
Replace: \1\t\2

RegEx : Remove line breaks if lookbehind shows a lowercase

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