In Visual Studio, would there be way to paste the clipboard text with modification? - visual-studio-2017

In Visual Studio, would there be way to paste the clipboard text with modification?
Basically I want to perform regex replacement (.*) and $1 kind of behavior without regex replacement.
For example, I would like to highlight text xxxx and replace it with /* obsolete xxxx */.
Pasting /* obsolete */ is not what I want to do because it is lacking xxxx
I cannot use regex listed above because I want to highlight any kind of word in the code.

Related

Regex and replace selected results only

I want to know whether there is any tool that does a regex search across huge text (xml or tagged or html) and replace only the cases which are selected across shown (should have 'select/deselect/select all' options while applying the replace regex).
Like the below example:
My content is:
"Visited xtreme.com, stupid.net, childish.com, happy.net and innocence.edu. There are some cross.network isssues that are to be fixed."
Now in this content, i want to replace all ".net" occurrences with ".com" and so a simple tool like notepad++ would replace it easily. But i want the tool to show the search results and give the option to replace only first two occurrences of ".net" and not the instance in "cross.network"
This is only example purposes only and don't suggest an alternate regex. I don't need it.
NP++ or sublime are all fine, as long as they can read all the text to the memory. They both support regexes for finding and replacing text.
If the text files are too big, i.e. NP++ crashes, then you can use sed. It's a command line tool that can replace text like this:
sed -i filename.txt 's/pattern/replacement/g'
On windows boxes you need mingw or cygwin to run it.
Use a text editor like sublime and apply a word boundary to the regular expression:
\.net\b
This will find .net in stupid.net but not in cross.network.
See a demo on regex101.com.

Notepad++ Regex inverse match

I'm new to Regex and trying to figure out how to remove all text from file open in Notepad++ that does not match #LCxxxx or #LAxxxx. Example below (text wanting to keep in bold):
1.In rare cases, reinstalling this MSP file can cause the Citrix Display Driver.....
[From ICAWS760WX86][#0528688]
30.This release includes an enhancement...
[From ICAWS760WX86022][#LA3014]
New Fixes in This Release
1.Windows Server 2008 R2 and Windows Server 2012 R2,...
[From ICAWS760WX86026][#LC2179]
Fixes from Replaced Hotfixes
1.If the Windows Remote Desktop Session Host....
[From ICAWS760WX86004][#LC1180]
I think this is what you're looking for:
(?:[\S\s]*?)(\#L[AC]\d{4})(?:.*)
Replace with:
$1\n
You could do a regular expression search and replace, searching for
(#L[AC]....)
where "dot matches newline" is NOT selected. Replace with
\r\n\1\r\n
That will put all the wanted pieces of text on a line on their own.
Next use the "Mark" tab in the find window. Select "Bookmark line", use the same search string as above (the capture brackets are not needed this time, but they are harmless and so can be left), and them click "Mark all". Now all the wanted lines are bookmarked. Use menu => Search => Bookmark => Remove unmarked lines.
There may be a way of doing it all in one go, but that would be a complex regular expression. The method above uses two simple steps.
remove all text from file open in Notepad++ that does not match #LCxxxx or #LAxxxx
^.*(\[#L[CA]\d+\])$|^.*$
DESCRIPTION
DEMO
https://regex101.com/r/hO1aL8/2
Notepad++
Do a search and replace like describe in the screenshot below:
Alternatively, if you want to get rid off the empty lines during the replace operation, use the regular expression below:
^[\S\s]+?(\[#L[CA]\d+\])$
\s : Whitespaces (\t,\r,\n ...)
\S : Any character except whitespaces.
Tested on Notepad 6.6.9

Multiline search replace with regexp in Eclipse

Eclipse regexp search works pretty well, so for example in search box I have this:
(?s)(myMethod.*?;)\}\);
Now I want to copy multiline text in the IDE and in replace box, for example I want to paste \1PASTE_MULTILINE_TEXT_HERE. However Eclipse does not allow me to directly copy-paste multiline text without manually inserting newline characters.
In Vim (Gvim, Macvim) it works perfectly well, keeping all the spaces; how can I do the same thing in Eclipse?
For searching multiple lines in Eclipse, you must use the 's' parameter in search expression:
(?s)someExpressionToMatchInAnyLine
For replacing with multiple lines exp you must use \R i.e:
line1\Rline2\Rline3
This will replace the matched exp with:
line1
line2
line3
Generally, the approach I've taken to doing this sort of thing is to type out what I want to use as a replacement, select that, open up the Find/Replace dialog, and copy the contents of the Find text box. I proceed from there and paste what I copied into the Replace text box. There is still a little work to be done (removing backslashes from in front of regex special characters that don't apply in the Replace box), but it gives me a hand up.

Visual Studio append text to end of lines using find/replace with end line regular expression ($)

I am trying to append some text (e.g. "Fish") to the end of every line in a file using Visual Studio or SQL Server Management Studio using the following settings in the find/replace dialog:
Find what: $
Replace with: Fish
Use Regular expressions: Checked
This mostly does the job, but for a handful of lines it not only appends "Fish" to the end of the line it also puts it at the beginning of the line. I can't discern any pattern to this behaviour it seems to be almost random, with the larger the file the more lines tending to go wrong.
A similar find/replace with ^ (to put text at the beginning of the line) works with no problem.
Anybody know why this is happening? And also, are there any better suggestions for achieving what I want to?
This works in Visual Studio 2012 and 2015:
Find: \r
Replace: Fish\r
Make sure you tick 'Use Regular Expressions' checkbox:
I'm not sure why you're seeing that, but you might try something like:
Find: ^.*$
Replace: \0Fish

How do I convert strings in code to uppercase in Visual Studio?

I'm trying to convert all character strings that match a particular regex in a file to uppercase, but I can't find the syntax to specify that within the 'Find and replace' window in Visual Studio. Is it possible to do this using the Visual Studio regex?
As JaredPar has expained, this cannot be done using a generic regular expression search/replace. However, I guess you should be able to do this using a macro.
It's not possible to do this as a generic replacement using Visual Studio regular expressions. It is possible to re-use the captured text as part of a replacement string using the \n escape sequence where n represents the nth group of captured text. However the regex language only supports limited modifications on this text (mostly justification changes). It doesn't allow you to change case.
Here is a link to the Visual Studio regex language
http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx
press alt + 'e' when the find window has focus to enable "regex" searches.
naturally, you can't 'program' a set of replacement options to insert based on what is found. Each replacement set would require one pass.