I am trying to remove whitespaces but not new lines in my text file in sublime text
I tried doing a find and replace of \s with nothing, but it also removes new lines, how can I remove whitespaces excluding new lines?
You can use a negative lookahead:
(?!\n)\s
Replace \n by some unique string like 1#3## (which would not be present in your document) and then replace \s by nothing and then finally replace 1#3## by \n
Related
My problem is that I have a csv-file with alot of new line. How can I remove the newlines with select and replace? My other stuff should stay how it is.
Here the example:
101080;101080;101080;104;
101098;101098;101098;105;
101099;101099;101099;106;"RING 750GG 1BRI TW VS 0,0300ct 1 RUBIN WEITE58.0
BREITE 4.5mm
72-91872-0-0 045-71-0-58-3
704.- VP1000.-
";
1011;1011;1011;106;
101093;101093;101093;123;
I have all over the csv file these new lines. I need to make that in 1 line.
thank you for the help
If I understand the question correctly, you only wish to remove the newlines for any lines that do not end in a semicolon character. You can do that below with this Find and Replace in Notepad ++ using the Regular Expression Search Mode.
Find: ([^;]$)(\r\n)
Replace: \1
Explanation of the find is that it is looking for the end of line and newline character that isn't preceded by a semicolon character. The parenthesis tell the find to group the results, which allows us in the replace to just keep the first grouping of find results and to discard the newline characters for these lines that don't end in a semicolon, which will then end up making it all line up on the previous line.
Here is a simple solution:
Activate the ShowAll Icon (ΒΆ) in the toolbar of Notepad++
Mark a ; and NewLine-Sequence (CR LF) in your file
Use the shortcut Ctrl + F
Select the Replace tab in the appeared search window
Insert ; in the Replace with text box
Press Replace All
Now all items ending with a ; are in single rows.
To remove all new lines: Just replace "\r\n" (windows) or "\n" (unix) with nothing! Using Extended or Regex options.
To just remove some:
First add unique data where you want to keep the new line - I use "QAZ".
Then remove all new lines as above.
Then replace "QAZ" with "\n".
It happens many times when we need to remove line end and unnecessary space between the HTML element. So this could be proven as a time-saving technique.
open Search and replace (CTRL+H)
enable "Regular Expression" (circled in red)
enter \n\s+ in the search field, clear the replace field
press "Replace all"
This will remove all newlines (\n+) followed by all whitespace (\s+) in the next line.
In your Sublime Text user settings, you can specify the following to trim trailing white space.
"trim_trailing_white_space_on_save": true
You might want to have a look at the Trimmer that has a couple of options to trim whitespace.
you can also use \n+ to remove all the unwanted space , if you want to use a single line then replace with \n online
I'm using Sublime Text and I need to come up with a regex that will find the whitespaces between a certain opening and closing tag and replace them with commas.
Example: Replace white space in
<tags>This is an example</tags>
so it becomes
<tags>This,is,an,example</tags>
Thanks!
You have just to use a simple regex like:
\s+
And replace it with with a comma.
Working demo
This will find instances of
<tags>...</tags>
with whitespace between the tags
(<tags>\S+)\W(.+</tags>)
This will replace the first whitespace with a comma
\1,\2
Open Find and Replace [OS X Cmd+Opt+F :: Windows Ctrl+H]
Use the two values above to find and replace and use the 'Replace All' option. Repeat until all the whitespaces are converted to commas.
The best answer is probably a quick script but this will get you there fairly fast without needing to do any coding.
You can replace any one or more whitespace chunks in between two tags using a single regular expression:
(?s)(?:\G(?!\A)|<tags>(?=.*?</tags>))(?:(?!</?tags>).)*?\K\s+
See the regex demo. Details
(?s) - a DOTALL inline modifier, makes . match line breaks
(?:\G(?!\A)|<tags>(?=.*?</tags>)) - either the end of the previous successful match (\G(?!\A)) or (|) <tags> substring that is immediately followed with any zero or more chars, as few as possible and then </tags> (see (?=.*?</tags>))
(?:(?!</?tags>).)*? - any char that does not start a <tags> or </tags> substrings, zero or more occurrences but as few as possible
\K - match reset operator
\s+ - one or more whitespaces (NOTE: use \s if each whitespace must be replaced).
SublimeText settings:
I am trying to make my regex work across multiple lines and "m" didn't seem to work either. So, my regex is working for 1st line and noT for the following lines.
You can skip the match part and just do it all in one step:
> "the *text* is to be replaced \n by *text*".replace(/\*([\s\S]*?)\*/g, '<i>$1</i>');
"the <i>text</i> is to be replaced \n by <i>text</i>"
. matches any character, but it excludes newlines. [\s\S] matches any character including newlines.
I changed your search regex to \*([\s\S]*?)\*, which non-greedily matches the stuff between the asterisks.
The replacement string is <i>$1</i>. $1 is replaced with the contents of the first capturing group, which is your text.
Also, because it looks like you're trying to convert Markdown to HTML, try using a pre-made JS converter: http://www.showdown.im/
You can use it like this:
var str = "the *text* is to be *replaced \n by* *text*";
alert(str.replace(/\*([\s\S]*?)\*/g, '<i>$1</i>'));
I am trying to index solar search from a built string in a code which has HTML tags. Any one knows how I can remove all the characters from the String.
Currently, I am using
answers << answer.feedback.replaceAll('\\<.*?>','')
I want to escape all the HTML characters and all the \n \t and \r. How to do this?
Do you want to escape the html tags so that <span> becomes <span> or do you want to REMOVE the tags themselves. Your original question is ambiguous.
For the first scenario:
answer.feedback.encodeAsHTML()
(see http://grails.org/doc/latest/ref/Plug-ins/codecs.html for further info)