Delphi IDE search using regular expressions - regex

I am in Delphi 10.2.2 Tokyo and trying to do a simple regular expression search. I'm sure I've done this before but it's not working.
It doesn't work whether I Ctrl-F search in the current source file or I Ctrl-Shift-F Find in Files.
I have researched this to make sure I understood the special characters & their meanings.
Anyway, search string fun.*e I assume will find any function declaration with an e in its name.
It finds nothing! I have tried a variety of searches like this - they all are finding nothing.
Case sensitive unchecked.
Whole words unchecked.
Search selection unchecked.
Entire scope checked. (for Ctrl-F, in current source file, search)
And, of course, Regular expression checked.
If I Search in Files I get the Search string 'fun.*e' not found popup. Period.
However, if I Ctrl-F I am seeing (current unit) 31 matches found in dark green down in the "search bar" and if I scroll through the unit, I am seeing the matches (highlighted in orange). But the cursor does not move to the first (or any) match. If I hit F3 immediately after doing the search (and seeing 31 matches found) I am getting the Search Match Not Found Restart search from the beginning of the file? popup. And if I say Yes I am back to seeing Search string 'fun.*e' not found!
I don't know if I might've changed some setting or option or whatever. I cannot imagine that I have. But I need to use Regular Expressions for searching.
FWIW, "normal" searches are working fine (whether Regular expression is checked or not).

I had Tools | Options | Editor Options | BRIEF regular expressions on.
Turning this off has fixed my issue.

Related

Search in VSCode for the multiline contents of a set of XML tags, using a regular expression

I am using VSCode to do a global search of XML files. Within those files there are multiple instances of these XML tags: <translated></translated>. I need to find all occurrences of any hyphens - that exist anywhere between those tags, where the contents of those tags can be on multiple lines.
<translated>
Content is here
Could be on multiple lines
The meeting could take 3-4 hours
</translated>
In the above example, the phrase "3-4 hours" has a hyphen in it. I need a regex that works for VSCode which finds all incidences of hyphens which happen to be within a set of these XML tags.
Option 1 (using VS Code)
This only matches one dash at a time and not all dashes. This is because limiting the search to inside one set of tags means it can only do one pass at a time. I was going to delete this answer but if it's the only answer given it may be better than nothing. The work around would be that you would have to refresh the search (button above the search box) and click replace all over and over. If there are lots of dashes this would be annoying but better than no answer.
I have been fiddling with Visual Code Studio and the following seems to work.
(<translated>(.|\n)*?)(-)((.|\n)*?<\/translated>)
Assuming you may be wanting to, for example, replace the dash it's possible to with adding back groups 1 and 4 wrapped around any new text...
$1 <yourTextHere> $4
Example:
Before replace:
After replace (note only the 3-4 in the first section of the file(s) is affected and the 3 to 4 is not changed):
Option 2 / Update (using Brackets.io)
While I'm unsure of the cause if the failure for VSCode to match across files, the following regex works with Brackets (google Brackets.io) across multiple files...
-(?=[^<]*?<\/translated>)
You have to have all your files in a folder and open the folder. Then search in the project (Find > Find in files). Notice in the screenshot it shows for the matches found across all files. In the lower panel for the selected file t2 copy.txt it matches first on line 6 and then on line 16 and (correctly) does not match on line 10 because it is not contained in a translated tag set.
The reason why -(?=[^<]*?<\/translated>) doesn't work in vscode is because it does not EXPLICITLY contain a newline \n. Even though [^<] includes newlines, the \n needs to be actually written into the regex in order to trigger the multiline option. Why is this?
See https://github.com/microsoft/vscode/issues/75265 which uses a similar regex. The issue makes for interesting reading ;>} Primarily for performance reasons.
So simply using this
-(?=[^<]*?\n*<\/translated>)
works in vscode!
-(?=[^<]*?\n<\/translated>) would work for you too unless you have single line blocks like:
<translated>Con-tent is he-re</translated>

Search not finding anything even when matching text is highlighted?

Just tried searching for a keyword in an XSLT file and it returned no results, despite highlighting the word about a dozen times in the file anyway.
Visual Studio clearly thinks the word cannot be found in the file, yet to the left you can see it's also highlighted matching text. "Find" and "Find All" return the same results. I haven't made any changes to my settings, so I don't know where to go prodding for search options to see if something's been changed by company policy or some other similarly daft reason.
I think you might be running up against a slight anomaly in the Quick Find functionality. When you first select Quick Find, if you have text selected in the editor window, the selected text appears as the search phrase and all instances are highlighted. But if you turn on a filter (such as Case Sensitive or Whole Word), some (possibly all) of the highlighted text instances no longer match the search string.
Try this:
Highlight a word in your code.
Click Find and Replace > Quick Find. All instances of the word are highlighted.
Now turn on Match Case, and change one letter in the search box so it is a capital letter.
Click Find. All instances of the word remain highlighted, but the "No results" dialog appears.
The problem is compounded by the fact that the little filter icons in the Quick Find window are difficult to interpret.

Does Adobe Brackets maintain any kind of history of search and replace expressions?

Just now I was working on a fancy search and replace regular expression.
It looked good so I tested it on one entry then went to the editing area and the search and replace box went away.
I reopened the search and replace box to continue, but the selected text in the edit window replaced my search expression.
Control Z in the search box did not go back to my regex but undid the last change in the editing area.
I can't seem to find a way to get back to previous regexes in the find box. Is there any way? Googling turned up nothing.
Currently, Adobe Brackets doesn't maintain any kind of history of search and replace expressions. The feature is still missing.

How to effectively search and replace in Vim by first "testing" or "preview" the search part?

Sometimes I want to search and replace in Vim using the s/search_for/replace_with/options format, but the search_for part becomes a complicated regex that I can't get right the first time.
I have set incsearch hlsearch in my .vimrc so Vim will start highlighting as I type when I am searching using the /search_for format. This is useful to first "test"/"preview" my regex. Then once I get the regex I want, I apply to the s/ to search and replace.
But there is two big limitation to this approach:
It's a hassle to copy and paste the regex I created in / mode to s/ mode.
I can't preview with matched groups in regex (ie ( and )) or use the magic mode \v while in /.
So how do you guys on SO try to do complicated regex search and replace in Vim?
Test your regex in search mode with /, then use s//new_value/. When you pass nothing to the search portion of s, it takes the most recent search.
As #Sam Brink also says, you can use <C-r>/ to paste the contents of the search register, so s/<C-r>//new_value/ works too. This may be more convenient when you have a complicated search expression.
As already noted, you can practice the search part with /your-regex-here/. When that is working correctly, you can use s//replacement/ to use the latest search.
Once you've done that once, you can use & to repeat the last s/// command, even if you've done different searches since then. You can also use :&g to do the substitute globally on the current line. And you could use :.,$&g to do the search on all matches between here (.) and the end of the file ($), amongst a legion of other possibilities.
You also, of course, have undo if the operation didn't work as you expected.
As the others have noted I typically use s//replacement/ to do my replacements but you can also use <C-r>/ to paste what is in the search register. So you can use s/<C-r>//replacement/ where the <C-r>/ will paste your search and you can do any last minute changes you want.
<C-r> inserts the contents of a register where the cursor is
The / register holds the most recent search term
:registers will display the contents of every register so you can see whats available.
Since Neovim 0.1.7 there is the Incremental (“live”) :substitute function. (so this only works in Neovim!)
To enable it set the incommand option:
:set inccommand=split
It was announced here: https://neovim.io/news/2016/11/

search in visual studio using regexp

I have a situation where i need to search for couple of objects in my code files. currently i m doing it by seaching using visual studio search option for every text i want to search.
I want to use regular expression ( search -> use -> regular expression ) to search all my text at once using OR operator.
Please suggest me for that, as i am not much familiar with regular expression syntax.
Sry for editing in question itself..
I got the answer. Like if I want to search for objects 'abc','xyz' I would put abc|xyz in visual studio seach box. But i don't know how to make this search case insensitive. I got a hint of using /i or -i or ?i , but where and how - i don't know .
As far as I know, Visual Studio should search case insensitive, unless you check the box that says "Match case" (see screenshot).
You can use the alternation operator | to effectively OR part of the regex. So (foo)|(bar) will find either the text "foo" or the text "bar". Either side, can of course, be a regular expression on its own, so you can come up with some pretty complicated stuff.
But as zzzzBov said, if you want any more help you're going to have to supply more information. Or you could actually, you know, read the documentation.
I've found that the search in file using regular expression is buggy in regard to case sensitivity in Visual Studio 2015. Even with the "Match case" option turned on, it will match text ignoring case by default.
The one trick that somehow fixed this is by using capture, surrounding the literal text you want with parenthesis in addition to the "Match case" option!
So instead of: abc.def
Use: (abc).(def)