I have a text that it is in one row. My purpose is to bring every new statement to a new row. After every "." symbol I want next statement to be on new row. How to achieve that. I have already tried to replace .\s* with .\n but that delete rest of text and just replace it with a "."
Use the Notepad++'s Regular Expression search feature with ". matches newline" checked, Now type \.. in Find what and .\nText Text Text\n in Relace with and hit Replace all.
Updated
For every character including "-".
Find what: \.([^.]+),
Replace with: .\n$1
Use replace tool in Extended mode (not the regexp) and put "." to replace with "\n". Or escape the point which is a special character in regexp mode:
Related
I've been trying a few different ways to try and search and replace on excell to remove the last couple of characters.
For instance in one column I have product name S
I want to remove the " S" only.
I have tried some if formulas a swell and not had much luck. I'm assuming there is a simple regex that can be used for the search and replace e.g. " S/" that would just replace if its the last characters and has nothing after it.
Try using the SUBSTITUTE function and replace the letters you want to remove with a unique character/ word / space not appearing anywhere else in the booklet, depending on which part of the string you're trying to remove and what format you're trying to keep
then find and replace ( CTRL +F) that word with the black (space) character
see how to use SUBSTITUTE function here:
https://exceljet.net/excel-functions/excel-substitute-function
Since you are only interested in the end of the string, I don't think you need regex or anything too sophisticated.
If I understand correctly, you want to get the original string (product name S) up until but not including something that appears at the end (S). This means that in your example, you want the 12 leftmost digits: the digits of the original string (14) minus the digits of the pattern (2) - this would give you product name. If the original string does not end with the pattern, you want the original string.
Therefore, I suggest the following:
=IF(RIGHT("original string",LEN("pattern"))="pattern",
LEFT("original string",LEN("original string")-LEN("pattern")),
"original string")
Check these examples:
I'm fairly new to Vim and I haven't been able to find on this site how to search and replace with a varying part of a string. I need to apply a global edit to all times "SetTag("...")" appears with ... being any word. My edit is to add one more word after the second quotation mark. example: SetTag("err" + __LINE__ with the bolded part being what I need to add. Can anyone let me know how this is possible with a vim search command? Thanks!
nb: I assume "word" is any sequence of characters other than a doublequote character. Modify as needed.
:%s/SetTag("\([^"]*\)")/SetTag("\1" + __LINE__)/
the escaped parentheses grab the sub-match; the \1 in the replacement string is replaced by that sub-match.
My question is very simple:
Is there a shortcut in Sublime Text 3 which allows to remove blank lines in a selected text? (same for blanks in a line)
For instance, how to make this text:
a
b
c
To become:
a
b
c
And this line:
I need to remove these blanks.
to become this line:
Ineedtoremovetheseblanks.
You don't need a plugin to do this, a simple regex search and replace will do. First, select the text where you'd like to delete the blank lines. Then, select Find → Replace… (or, hit CtrlH on Windows/Linux, ⌘⌥F on OS X). Make sure the "Regular Expression" and "In selection" buttons are selected:
In Find What:, enter ^\n, and make sure the Replace With: field is empty. Then, simply hit "Replace All" and this:
becomes this:
As a bit of explanation, the regular expression ^\n searches for the beginning of a line (^) immediately followed by a newline character (\n). If you suspect that some of your "blank" lines contain whitespace, like space or tab characters, you can use ^\s*\n instead - \s* matches 0 or more whitespace characters, including newline characters.
For your second example, use the same Find/Replace settings as above, except your regular expression should simply be \s*.
There is a package called Trimmer. You can install it via Package control.
After you got the package you can use its functionalities. Just highlight the text you want to change (or don't select anything if you want to change the entire file) and then choose:
1) Edit > Line > Delete Empty Lines
2) Edit > Line > Remove Blank Spaces
Alternatively, as Chris's answer already pointed out you can use the classic search & replace functionality that is already present in the editor.
AS my original answer was incorrect, I have found this package which will be suitable for your needs.
The package is called DeleteBlankLines, for Sublime Text 3, has the ability to delete blank lines for the entire document and within the selected text only, all from a key stroke just like you were after.
The package can be found here:
https://packagecontrol.io/packages/DeleteBlankLines
I prefer using \s+, which will get one or more (i.e., the + character) whitespace characters (i.e., the \s escape sequence).
The * character will do zero or more, which on some versions can break up the individual words into letters.
In vim I have a line of text like this:
abcdef
Now I want to add an underscore or something else between every letter, so this would be the result:
a_b_c_d_e_f
The only way I know of doing this wold be to record a macro like this:
qqa_<esc>lq4#q
Is there a better, easier way to do this?
:%s/\(\p\)\p\#=/\1_/g
The : starts a command.
The % searches the whole document.
The \(\p\) will match and capture a printable symbol. You could replace \p with \w if you only wanted to match characters, for example.
The \p\#= does a lookahead check to make sure that the matched (first) \p is followed by another \p. This second one, i.e., \p\#= does not form part of the match. This is important.
In the replacement part, \1 fills in the matched (first) \p value, and the _ is a literal.
The last flag, g is the standard do them all flag.
If you want to add _ only between letters you can do it like this:
:%s/\a\zs\ze\a/_/g
Replace \a with some other pattern if you want more than ASCII letters.
To understand how this is supposed to work: :help \a, :help \zs, :help \ze.
Here's a quick and a little more interactive way of doing this, all in normal mode.
With the cursor at the beginning of the line, press:
i_<Esc>x to insert and delete the separator character. (We do this for the side effect.)
gp to put the separator back.
., hold it down until the job is done.
Unfortunately we can't use a count with . here, because it would just paste the separator 'count' times on the spot.
Use positive lookahead and substitute:
:%s/\(.\(.\)\#=\)/\1_/g
This will match any character followed by any character except line break.
:%s/../&:/g
This will add ":" after every two characters, for the whole line.
The first two periods signify the number of characters to be skipped.
The "&" (from what I gathered) is interpreted by vim to identify what character is going to be added.
Simply indicate that character right after "&"
"/g" makes the change globally.
I haven't figured out how to exclude the end of the line though, with the result being that the characters inserted get tagged onto the end...so that something like:
"c400ad4db63b"
Becomes "c4:00:ad:4d:b6:3b:"
I have a text document that has blank lines and lines that start with capitalized months.
I want to add "- " to the beginning of each non-blank line.
Tried this:
1,$s/^[A-Z]/- /
and it removes the first letter of the month (e.g. "- une" when it should be "- June")
How can I add that letter back? Or is there a "better" way of doing this for a large document where I need to keep the blank lines untouched.
try this, it should give what you want
%s/^[A-Z]/- &/
or use :g:
:g/^[A-Z]/s/^/- /
You have an answer that would either add the matched text back in, or avoid matching the text altogether during the substitution. Another method is to specify the match as zero-width, or set the ending of the match, so that the text is matched but not replaced:
%s/^[A-Z]\#=/- /
or
%s/^\ze[A-Z]/- /
See :help zero-width, :help /\#=, :help /\ze.