Поиск в Delphi. Часть 1: Регулярные выражения

Malcolm Groves, “Searching in Delphi Part 1 : Regular Expressions”, public translation into Russian from English More about this translation.

See also 15 similar translations

Translate into another language.

Participants

r3code1042 points
Bosonojka101 points
Dimbuch23 points
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2 3 4

Searching in Delphi Part 1 : Regular Expressions

Поиск в Delphi. Часть 1: Регулярные выражения

History of edits (Latest: r3code 2 years ago) §

Being able to find elements in your code quickly and easily is critical to being productive in any IDE. Spend too long looking for things and you start to lose your train of thought. Over the years Delphi has introduced lots of different ways to search your code, some of them simple text-based matching, some of them much more capable search engines that actually understand the structure of your code. However, I regularly meet developers who aren’t aware of many of them, beyond doing a simple search using the Search | Find (Ctrl-F) menu option, or the same across multiple files using Search | Find in Files (Shift-Ctrl-F).

Возможность быстро и легко найти что-то в своем коде очень важна для любой IDE. Проводя слишком много времени в поисках чего-то Вы теряете свои мысли. На протяжении многих лет Delphi представлял множество различных способов поиска в Вашем коде, некоторые из них - простое текстовое соответствие, другие намного более мощные поисковые системы, способные понимать структуру Вашего кода. Как бы то ни было, я постоянно встречаю разработчиков, которые не знают о многих из них, разве что только о простом поиске с использованием пункта меню Search | Find (Ctrl-F) , или же о поиске по нескольким файлам с помощью Search | Find in Files (Shift-Ctrl-F).

Unapproved edits (Latest: r3code 1 year, 11 months ago) §

Starting with this post I’m going to try and address some of that. Each post will focus on a different way to find things in your project. I’m going to assume, however, that everyone can use the basic Find and Find in Files functionality, so I won’t cover that. However, I will start by covering one feature of both of those text-based searches that seems to be underused : Regular Expressions.

Начинаясь с этого поста я собираюсь попробовать и обратиться к части этого. Каждое сообщение будет посвящено различным способам, чтобы найти то что вам надо в вашем проекте. Я буду считать, однако, что каждый может использовать просто средства Find и Find in Files, поэтому я не буду рассматривать это. Тем не менее, я начну с рассмотрения одной возможности обоих этих средств поиска, которые недостаточно используются - это регулярные выражения.

History of edits (Latest: r3code 1 year, 11 months ago) §

When doing a text-based search, usually the more specific you can be with your search string, the fewer false matches (ie. matches that you are not actually looking for) you’ll get. Problem is you often either don’t know enough of the exact text around your match, or you’re trying to match multiple lines with different text around your string. So you end up with a not very specific search string, and so many matches you waste a bunch of time trying to find the relevant ones, or worse, miss some relevant ones amongst the deluge.

При выполнении текстового поиска, как правило, чем конкретнее вы зададите строку поиска, тем меньше ложных совпадений вы получите (т.е. совпадения, которые вы на самом деле не ищете) . Проблема в том, что Вы часто либо не знаете, насколько точно совпадает введенный текст с искомой строкой, либо Вы пытаетесь найти соответствие нескольким строкам с разным текстом рядом с вашей строки. Таким образом, вы в имеете не очень конкретную строку поиска, и множество совпадений на которые вы тратите кучу времени, пытаясь найти соответствующие искомому, или что еще хуже, пропустить некоторые важные среди этого множества.

History of edits (Latest: Dimbuch 1 year, 3 months ago) §

You’re probably never going to get the perfect result of just the items you’re looking for. It ends up being a trade-off between the time spent creating the search string vs the time spent wading through the results, and often a good enough balance, is, well, good enough. This is where regular expressions can help

Возможно, вы никогда не получите безупречный результат, содержащий только то, что вы ищете. Это заканчивается компромиссом между временем на создание строки поиска и временем на поиск по результатам, и часто достаточно сбалансировано, достаточно хорошо. Это то, где регулярные выражения могут помочь

History of edits (Latest: r3code 1 year, 11 months ago) §

Let me give you a concrete example.

Позвольте мне привести вам конкретный пример.

History of edits (Latest: r3code 1 year, 11 months ago) §

The DUnit framework makes heavy use of an interface called ITest. Let’s say you want to find all places in TestFramework.pas where an ITest is passed in as a parameter to a method.

Фреймворк DUnit интенсивно использует интерфейс, который называется ITest. Допустим, вы хотите найти все места, где в TestFramework.pas ITest передается в качестве параметра метода.

History of edits (Latest: r3code 1 year, 11 months ago) §
Pages: ← previous Ctrl next next untranslated
1 2 3 4