Regex pattern search in TextPad fails, works in Visual Studio - regex

I'm trying to use TextPad to search for a regular expression in several files. I have a simple pattern but it doesn't work in TextPad. It works fine in Visual Studio.
Anyone have any ideas?
I'm searching for:
hosted.mysite.com or host.mysite.com
using the pattern:
(hosted|host)\.mysite\.com

Use something like this
\(hosted\|host\).mysite.com

try this:
host\(ed\)?\.mysite\.com

Not every text editor uses the same regex/conventions. A regex you may get to work in Visual Studio won't necessarily work in Eclipse, Netbeans, or some other IDE or text editor.

In Textpad you need to escape some characters, such as parenthesis and pipes.
In your case, what you need is this:
\(hosted\|host\)\.mysite\.com
Note: you need to escape dots as well.

Textpad's POSIX regexes are good, but even better results could be achieved by installing the Win GNU util grep and adding a cmd /c "Prompt for parameters " , "Capture output" command: thus you could have full Find in files with even Perl regexes:
grep -nhPr "CoolRegexToSearchWith" C:\MyDir\ToSearchRecursivly

Related

Find and replace pattern in large number of files

I want to replace text in about 80.000 log files using a regex. I love the batch search and replace of VSCode. I was unable to do this with VSCode, because it did not seem to handle this amount of data well. Any suggestion how I could do this with VSCode? Are there suggestions for alternatives?
Instead of depending on a GUI based tool, it might be easier to for a CLI tool for this.
If you're using Linux, or willing to install any of the tools like sed and find if you're on Windows then it should be relatively simple.
You can use sed which is a command line tool on all (or at least most) distributions of Linux, and can be installed on Windows.
Usage (for this use case):
sed -i s/{pattern}/{replacement}/g {file}
Use sed to replace the matched pattern with a replacement, using the global modifier to match all results, and the file to do the replacement and overwrite.
To target all files in a directory you can do:
find -type f -name "*.log" exec sed -i s/{pattern}/{replacement}/g {};
Find items recursively starting from the current directory where it's type is file, and it has a name ending with .log. Then use sed to replace the pattern with the contents you want for each matched file.
You can find how to get tools like sed and find for Windows on the following question:
https://stackoverflow.com/a/127567/6277798

Geany "Find in files" breaks when brackets included in search string

I have Geany 1.27 installed in my UbuntuĀ 14.04 (Trusty Tahr). But I also have Windows 7 OS with Geany 1.28 installed.
In both these versions of Geany, when I try to find a string into a multiple files or folder with file-type filter of "phtml" or "php", I see that when my search string includes ( or ) (for example, function new() the search fails.
Now I have a slight idea that this could be due to un-escaped bracket in string acting as part of Regex in grep command. Am I right?
How can I overcome the unescaped characters in search string when searching in Geany? In both Ubuntu and Windows Geany if the method could be different.
Ensure you properly escape your braces, as depending on options, you have set the regular expression is used for searching.
Your function search would be something like new\(\). The documentation is more detailed.

Find and Replace brackets () with new Line in Visual Studio

I have to add some javascript code in VS 2013.
Before (Now)
Layout.init();
After (What I want)
Layout.init();
Side.init();
If there were no () I could do it with \n but VS do not find them.
How can I change them like latter?
edit:
I want to change all my project in every page with ctrl+H;
I can change with ctrl+H and regex enabled:;
find:
abc
replace:
abc
def
with this regex
replace:
abc \n def
when I try to change with () VS don't find any of them...
I'd suggest using Notepad++ > 'Find in Files' option to replace text in bulk. It works for files inside a specific directory or if needed, can traverse all sub-directories and replace them. See the below snapshot for settings needed
I recommend you free Multiline Search and Replace Visual Studio extension. It supports Find/Replace in files.

Regular expression search and replace in multiple files (bulk) - without opening files

I normally use Notepad++ to search and replace what I need (regex), however, I have to open all the files that I need, in order to replace what is needed to be replaced.. My question is how can I do that in bulk (multiple) files, in a folder, without opening any of the files? Is there a good freeware to do that with? or something like creating .bat or .pl file, and run it in the folder to execute the replace? If so, how can it be done?
Simple example:
<b>(\d+\. )</b>
to
\1
This regex removes the bold tag in numbers.
How can it be done for bulk files without using NP++ under Windows?
Use Notepad++'s own Find in files function, that you can find in the Find menu.
This can be done with this perl oneliner:
perl -pi.back -e 's#<b>(\d+\.\d+)</b>#$1#g;' file*
This will process all files that have their name beginning with file and save them before into fileX.back.

What is a regular expression I can use in Vim to find CVS conflicts?

What is a regular expression I can use in Vim to find conflicts in CVS and possibly other version control systems?
Here is a regular expression to find entire conflict sections:
[<]\{7}.*\_.\{-}[=]\{7}\_.\{-}[>]\{7}.*
And to search for that in vim, just press the '/' key and paste that regular-expression string, then press enter.
Usually CVS conflicts look like this:
<<<<<<< file.c
Code from file.c
=======
Code from the repository version 1.2
>>>>>>> 1.2
Vim search-and-replace command to keep local version:
:%s/[<]\{7}.*\n\(\_.\{-}\)[=]\{7}\_.\{-}[>]\{7}.*\n/\1/g
Vim search-and-replace command to keep repository version:
:%s/[<]\{7}.*\_.\{-}[=]\{7}\n\(\_.\{-}\)[>]\{7}.*\n/\1/g
I usually just do /<<< and press 'n' until I find no more matches. It is a much less sophisticated approach than Neil's, but it works for me :)