Solutions Products Download Purchase Support News Members Company
SITE FEED
Support Forum
The fastest and most effective to get answers to your questions quickly.
FAQs
Quick answers to common questions.
Troubleshooting
Known issues and basic troubleshooting techniques for problems or unexpected behaviors.
Knowledgebase
Technical tips, How-to articles, and other tutorials about ApexSQL Tools.
Online Documentation
All of our help files for download or convenient viewing online.
Videos
Watch product demos, training videos, or tutorials of our products' main features. 

ApexSQL Knowledgebase

Tips and How-to Articles for Apex SQL Tools


Regular expressions patterns for objects filtering

DESCRIPTION
Regular expressions are used to specify patterns for text searching and processing. This KB discusses regular expressions and how to use them for object filtering in ApexSQL Tools.

Definitions

A regular expression (regex or regexp for short) is a special text string for describing a search pattern.

A match is the piece of text, or sequence of bytes or characters that pattern was found to correspond to by the regex processing software.

A word character is an alphanumeric character in the alnum class or an underscore (_).

A word boundary is generally defined as a location where there is a "word character" on one side, and not on the other and designated by \b.

Assertions

Assertions specify the position of match for the pattern:

\b - A match must occur at a word boundary

a. \b(Cu) matches the tables with the names starting with “Cu”



b. (Currency)\b matches the tables finished with “Currency”



\B - Specifies that the match must not occur on a \b boundary.

a. (History) matches tables with names containing “History” substring anywhere



b. (History)\B matches tables containing “History” in the middle



^ - Specifies that match must occur at the beginning of a string.



$ - Specifies that match must occur at the end of a string.



For more information on assertions please refer to: http://msdn2.microsoft.com/en-us/library/h5181w5w(VS.71).aspx

Character Class

A Character class is a pattern in a regular expression that matches any of a set of characters. To match an “a” or an “e”, use [ae]. You could use this in gr[ae]y to match either “gray” or “grey”. The order of the characters inside a character class does not matter.



a. The \b(C[ou][ulnr])\w+ pattern matches the strings that start with the “C” character followed by second “o” or “u” characters followed by third “u”, “l”, “n” or “r” characters and followed by one or more word characters.



b. The Sales…son pattern matches the strings containing substring “Sales” followed by any three characters followed by “son” substring.



Grouping Constructs

Grouping constructs allow you to capture groups of sub-expressions.



a. The \b(Sales) pattern matches to strings started with “Sales”



b. The \b(?!Sales)\w+\b matches strings that not started with “Sales”



c. The Sales(?!Person) pattern matches strings containing “Sales” substrings followed by any but “Person” substring.



Quantifiers

Quantifiers add optional quantity data to a regular expression. A quantifier expression applies to the character, group, or character class that immediately precedes it. The .NET Framework regular expressions support minimal matching ("lazy") quantifiers.



a. The (Product){2} pattern matches strings with exact two “Product” substring repetitions.



b. The (Product)+ pattern matches the strings with at least one appearance of “Product” substring.



Escape Characters

An escape character signals to the regular expression parser that the character is not an operator and should be interpreted as a matching character.
The escaped character \b is a special case. In a regular expression, \b denotes a word boundary (between \w and \W characters) except within a [] character class, where \b refers to the backspace character.
In a replacement pattern, \b always denotes a backspace.



Filtering objects with the regular expressions in ApexSQL applications

The result object selection set is a union of those subsets that are specified by the regular expressions patterns.

For example the pattern S[^h]\w+ specifies a string where “S” character is followed by any character but “h” after which any word character may exist:



The pattern S[^a]\w+ specifies a string where “S” character is followed by any character but “a” after which any word character may exist the:



As a result the total objects selection specified by applying both of the patterns includes sub-sets that were excluded by each of the patterns.



More information

1. Teach Yourself Regular Expressions in 10 Minutes by Ben Forta
2. Mastering Regular Expressions by Jeffrey Friedl
3. MSDN Library: Regular Expressions Language Elements

AUTHOR
Irene Sanford

LAST REVIEW DATE
31 August 2007

Labels:



© 2010 Apex SQL Tools All Rights Reserved | 1.919.968.8444 | Contact Us | Terms of Use | Privacy Policy