Tips n Tracks

  • Increase font size
  • Default font size
  • Decrease font size
  • default color
  • black color

Reference

Sample image

Microsoft .NET Framework Get Details.

Sample image

Microsoft .NET Framework Get Details.

Reference

Sample image Microsoft .NET Framework Get Details.
Sample image

Microsoft .NET Framework Get Details.


Archive for May, 2009

Text and Data Manipulation with Regular Expressions in .NET Development


Text and Data Manipulation with Regular Expressions in .NET Development

Regular expressions(or regex) is a language used for more sophisticated form and text processing. They are often used to perform complex search-and-replace operations, and to validate that text data is well-formed. Today, regular expressions are supported by most programming languages, as well as many scripting languages (like Perl, ASP, Visual Basic, .NET, C#, Java, JSP, PHP,Python, ColdFusion, Tcl, Ruby and many other languages), editors (EmEditor, TextPad), applications (Microsoft Word, Microsoft Excel, StarOffice, OpenOffice), databases(MySQL, SQL Server), and command-line tools.

Here we see a hands on approach to solve the needs of the majority of RegEx to manipulate data. I have try my best to provide ready to use source for lattest version of ASP.NET, VB.NET, C#.NET. All the example described here are tested with Visual Studio 2008. I have try to cover all important and mostly used regular expressions. If you face with any error or you have new idea which needed to be cover here. Please drop your feedback for me. Ok!, let’s get started…


Read the rest of this entry »

Using Regular Expressions Metacharacters with .net – Greedy and Lazy quantifier


Using Regular Expressions Metacharacters with .net – Greedy and Lazy quantifier

When a regular expression has a quantifier that can accept a range of repetitions (like ".*"), the normal behavior is to match as many characters as possible. Consider the following regular expression:

a.*b The longest string starting with a and ending with b

If this is used to search the string "aabab", it will match the entire string "aabab". This is called "greedy" matching. Sometimes, we prefer "lazy" matching in which a match using the minimum number of repetitions is found. All the quantifiers in Table 2 can be turned into "lazy" quantifiers by adding a question mark "?". Thus "*?" means "match any number of repetitions, but use the smallest number of repetitions that still leads to a successful match". Now let’s try the lazy version of example:

a.*?b The shortest string starting with a and ending with b

If we apply this to the same string "aabab" it will first match "aab" and then "ab".


Read the rest of this entry »

Using Regular Expressions Metacharacters with .net – Captures


Using Regular Expressions Metacharacters with .net – Captures

(exp)

(exp) – Match exp and capture it in an automatically numbered group. Common, unadorned parentheses generally perform two functions, grouping and capturing. Common parentheses are almost always of the form (), but a few flavors use \(\).

(?<name>exp)

(?<name>exp) – Match exp and capture it in a group named name. .NET languages support captures to named locations.

(?:exp)

(?:exp) – Match exp, but do not capture it, but, as the name implies, group regex components for alternation and the application of quantifiers. They are not counted as part of $1, $2, etc. After a match of (1|one)(?:and|or)(2|two), for example, $1 contains ‘1′ or ‘one’, while $2 contains ‘2′ or ‘two’. Grouping-only parentheses are also called non-capturing parentheses.

Using Regular Expressions Metacharacters with .net – Comments and Mode Modifiers


Using Regular Expressions Metacharacters with .net – Comments and Mode Modifiers

With many flavors, the regex modes and match modes described earlier can be modified within the regex by the following constructs.

Mode modifier: (?modifier), such as (?i) or (?-i)

Many flavors now allow some of the regex and match modes to be set within the regular expression itself. A common example is the special notation (?i), which turns on case-insensitive matching, and (?-i), which turns it off. For example, <B>(?i)very(?-i)</B> has the very part match with case insensitivity, while still keeping the tag names case-sensitive. This matches ‘<B>VERY</B>’ and ‘<B>Very</B>’, for example, but not ‘<b>Very</b>’.

This example works with most systems that support (?i), including Perl, PHP, java.util.regex, Ruby,[] and the .NET languages. It doesn’t work with Python or Tcl, neither of which support (?-i).


Read the rest of this entry »

Using Regular Expressions Metacharacters with .net – Lookahead and Lookbehind Zero-Width Assertions


Using Regular Expressions Metacharacters with .net – Lookahead and Lookbehind Zero-Width Assertions

Perl 5 introduced two very powerful constructs: "lookahead" and "lookbehind". Collectively, these are called "lookaround". They are zero-width just like other "zero-width assertions" don’t match actual text, but rather positions in the text. The difference is that lookarounds will actually match characters, but then give up the match and only return the result: match or no match. That is why they are called "assertions". They do not consume characters in the string, but only assert whether a match is possible or not. Lookarounds allow you to create regular expressions that are impossible to create without them, or that would get very longwinded without them.


Read the rest of this entry »