Is it possible to use "find and replace" in visual studio to insert \t into code?
Replacing with \t puts 4 spaces and replacing with \\t puts \\t.
(I am trying to run regex to format my "strings"..)
Don't know the firm answer to your question. But you can try something like this.
replace with foobart first.
use find and replace again to replace foobar with \.
Related
I think this is easier than I think, anyway I would like to know your ideas.
I have this file:
AVP78031.1
AVP78042.1
ATO98108.1
ATO98120.1
But I need to do this:
AVP78031.1
AVP78042.1
ATO98108.1
ATO98120.1
Is there a way in NotePad++ to do this? However, I think this type of edition could do it in Bash Script or even only with the terminal. Is there a way to do this?
If you think that there is another way easier to do this, please let me know.
Any suggestion is always welcome.
Thank you for your time!
Using Notepad++
Ctrl+H
Find what: (\R){2,}
Replace with: $1
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
(\R) # group 1, any kind of linebreak
{2,} # may appear 2 or more times
Replacement:
$1 # content of group 1, linebreak
Screenshot (before):
Screenshot (after):
I am new to writing in bash and I just finished this long script but I made the mistake of not adding quotation marks to all the variables beginning with the unary operator $. Adding all the quotation marks by hand is going to take a while. Is there a short cut I can use so all the words in the text file beginning with $ get quotation marks around them? So if a line in the file looks like:
python myProgram.py $car1 $car2 $speed1 $speed2
Then after the shortcut it will appear as
python myProgram.py "$car1" "$car2" "$speed1" "$speed2"
I am writing the script using nano.
Use global search and replace with the expression (\$\w+).
Switch to search and replace mode with C-\.
Switch to regex mode with Alt-R.
Type the expression (\$\w+). Hit Enter.
Type in the replacement expression "\1" replace the captured expression with quotations. Hit Enter.
On the match, hit A for All.
Given your need, it doesn't seem mandatory to provide a solution based on that editor. If you have access to a shell you might try this simple sed command:
sed -i.bak -r 's/\$\w+/"&"/g' my-script.sh
This is far from being perfect but should do the job in your particular case. If the above command:
-i.bak will perform the replacement "in place" -- that is modifying the original file, making a backup with the .bak extension
s/..../..../g is the usual sed command to search and replace using a pattern. The search pattern is between the first two \. The replacement is between the last two /
\$\w+ this pattern correspond to a $ followed by one or more letters (\w+). The backslash before $ is needed because that character normally has special meaning in a search pattern.
"&" is the replacement string. In there, the & is replaced by the string found in the search pattern. Broadly speaking this put quotes arround any string matching the search pattern.
i have multiple document which has lines which starts with blank space. those lines should be removed.
how can one remove a line which contains a blank space in the beginning and no other chars?
With Notepad++, you can use regular expression search and replace.
Go to Replace, select "Regular Expression" in the Search Mode box, and enter the following search expression:
\r\n \r\n
This means: newline, space, newline.
Replace by nothing. That should do the trick!
This is in Notepad++
Search
Replace
Find what: ^ +$
Replace with: (blank)
Search Mode: Regular expression
I my case regEx not solve the problem, I use plugin TextFX and I solve like this:
delete all spaces:
delete lines:
Find and Replace (Ctrl + h) than on Search Mode settings check Regular expression. After you sett the box to search with regex patterns enter this into the Find what field: ^([ ]+)$ and leave the replace field empty. Than click Replace All. That's it.
This will find all lines starting with a space character (may contain more that one space) but that have NO other character after the space/s.
Go to Edit-> Line Operations->Remove Empty Lines(Containing Blank Characters)
I have a piece of text that resembled the following:
==EXCLUDE
#lots of lines of text
==EXCLUDE
#this is what I actually want
And so I was trying to remove the unwanted bit by doing:
str.gsub!(/==EX.*?==EXCLUDE/, '')
However, its not working. When I tried to remove the \n chars first, it worked like a dream. The issue is that I can't actually remove the \n characters. How can I do a substitution like this while leaving newlines in place?
By default, the . does not match line break chars. If you enable the m modifier in Ruby (in other languages, this is the s modifier) it should work:
str.gsub!(/==EX.*?==EXCLUDE/m, '')
Here's a live demo on Rubular: http://rubular.com/r/YxLSB1Iq95
Try str.gsub!(/==EX.*?==EXCLUDE/m, '')
That should make it span new lines.
I am reading a file which has source code. I need to append 2 spaces before each line. This is what I am doing.
data = read_file
data.split(/\n/).collect {|l| ' ' + l}.join('\n')
However after joining when I do puts then it prints \n literally and it is not a line break. How do I fix that?
You need to use a double quote (") instead of a single quote. So replace this:
'\n'
with this:
"\n"
Read more about it here.
You might want to use \r\n instead if you want your line-endings to be CRLF instead of LF (some Windows editors such as Notepad won't see a LF linebreak).
I was able to finally get this to work for my application by using
"<br>"