(Created page with "<seo title="Maximize Regular Expression Matching | vEdit" description="Maximize your use and knowledge of Regular Expression matching while using vEdit's Search and Replace."...")
 
(Related Resources)
 
Line 29: Line 29:
  
 
==Related Resources==
 
==Related Resources==
 +
*[[Regular_Expressions|Regular Expressions Overview]]
 +
*[[Regular_Expressions_Basics|Regular Expressions Basics]]
 +
*[[Special_Matching_Characters|Special Matching Characters]]
 +
*[[Special_Matching_Characters#The_OR_Operator|The “OR” Operator]]
 +
*[[Groups_Replacement_Strings|Groups and Replacement Strings]]
 +
*[[Groups_Replacement_Strings#Groups_and_Replacement_Examples|Groups and Replacement Examples]]
 +
*[[Regular_Expressions_Newline|Matching the “Newline”]]

Latest revision as of 22:53, 6 February 2017


Regular expressions originally came from the UNIX environment and we have made every attempt to follow the UNIX definitions as closely as possible.

Another important rule about UNIX regular expressions is that the * and + operators always match the longest possible string that still allows the rest of the expression to match. Consider the rather subtle expression (already used in an example above):

{.*}\1

and the text line:

a00a abc12231223cba

On the first search, it will match the “00” in “a00a” since it matches any repeating text. However, on the second search it does not match the “22”, but rather the entire “12231223” because this is the longer repeating text string that includes “22”.

Although this is a useful and powerful characteristic of regular expressions, it is not always desirable. (It is also not intuitive.) vEdit lets you select either minimized or maximized regular expression matching in the Search dialog box. The default can be set with CONFIG > Search options > Default search mode.

When minimized, it would have matched “22” instead of “12231223” in the previous example. As another example, consider the search string:

a.+b

and the text:

12a3456b7890b

When minimized, it will match “a3456b”; when maximized, it will match “a3456b7890b”.

Using maximized regular expressions slows down searches significantly the search cannot stop on the first match, but must rather keep looking for ever longer matches. It is probably because of this characteristic that the original UNIX designers decided to restrict searches to a single text line a multi-line search for {.*}\1 in even a tiny 1-Kbyte file would involve over a million comparisons.

Related Resources