private string SplitCamelCaseToHumanReadable(string strCamelCase)
{
var rgx = new Regex(
@"(?<=[A-Z])(?=[A-Z][a-z])
| (?<=[^A-Z])(?=[A-Z])
| (?<=[A-Za-z])(?=[^A-Za-z])"
, RegexOptions.IgnorePatternWhitespace);
return rgx.Replace(strCamelCase, " ");
}
Showing posts with label Regex. Show all posts
Showing posts with label Regex. Show all posts
Friday, January 3, 2014
Friday, April 24, 2009
Regex - Expresso - winning regular expression development tool

Expresso is a free regular expression development tool. It's full-featured development environment for the experienced programmer who wants to code with knowledge of regular expressions and needs to test, analyze, and generate applicable and accurate regular expressions. Expresso code by Jim Hollenhorst.
It's an integrated regular expression editor, tester, analyzer with rich library of regular expressions ready to use for different categories.
To find out its features, look at the following link:
http://www.ultrapico.com/Expresso.htm
To download:
http://www.ultrapico.com/ExpressoDownload.htm
More links:
Expresso in www.codeproject.com
http://www.codeproject.com/KB/dotnet/expresso.aspx
The 30 Minute Regex Tutorial (by Jim Hollenhorst)
http://www.codeproject.com/KB/dotnet/regextutorial.aspx
Regex - Expresso - winning regular expression development tool
Sunday, April 19, 2009
Regex - Free sources about regular expressions

A very valuable source for regular expressions:
http://www.regexlib.com/
Regular expression cheat sheets:
http://regexlib.com/CheatSheet.aspx
OR
http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/
OR
http://opencompany.org/download/regex-cheatsheet.pdf
...
Regex - Free sources about regular expressions
Regex - Reformat a string by regular expressions
Sometimes we have strings with different formats but same meaning, then may be it's better to keep them all with an standard format in our report to keep consistency and make it easier for users.
One example is format of a phone number, the standard format can be considered as "(###) ###-####" and here we have a solution by regular expression even though that many different regular expressions would work.
Match m = Regex.Match(str,
@"^\(?(\d{3})\)?[\s\-]?(\d{3})\-?(\d{4})$" );
string newStr = String.Format("({0}) {1}-{2}",
m.Groups[1], m.Groups[2], m.Groups[3] );
In above regular expression pattern, each \d{n} part is surrounded by parenthesis which makes that part as a separate group (then each of items exists in Match.Groups array) that can be easily used using String.Format, another reformatting method is Regex.Replace, it's a static method and in the following example it replace dates in mm/dd/yy format to dd-mm-yy format:
string newStr = Regex.Replace(str,
@"\b(?\d{1,2})/(?\d{1,2})/(?\d{2,4})\b",
"${day}-${month}-${year}" );
In above pattern, ${day} inserts the substring captured by the group (?\d{1,2}) and so on.
Note: \b in above pattern specifies that the match must occur on a boundry between \w (alphanumeric) and \W (nonalphanumeric) characters. It means a word boundary, which are the first and last characters in words separated by any nonalphanumeric characters.

One example is format of a phone number, the standard format can be considered as "(###) ###-####" and here we have a solution by regular expression even though that many different regular expressions would work.
Match m = Regex.Match(str,
@"^\(?(\d{3})\)?[\s\-]?(\d{3})\-?(\d{4})$" );
string newStr = String.Format("({0}) {1}-{2}",
m.Groups[1], m.Groups[2], m.Groups[3] );
In above regular expression pattern, each \d{n} part is surrounded by parenthesis which makes that part as a separate group (then each of items exists in Match.Groups array) that can be easily used using String.Format, another reformatting method is Regex.Replace, it's a static method and in the following example it replace dates in mm/dd/yy format to dd-mm-yy format:
string newStr = Regex.Replace(str,
@"\b(?
"${day}-${month}-${year}" );
In above pattern, ${day} inserts the substring captured by the group (?
Note: \b in above pattern specifies that the match must occur on a boundry between \w (alphanumeric) and \W (nonalphanumeric) characters. It means a word boundary, which are the first and last characters in words separated by any nonalphanumeric characters.
Regex - Reformat a string by regular expressions
Regex - String input validation by regular expressions
Using regular expression is one of the most efficient ways to bring security to validate user input. As an example, the following regular expression works to match valid names:
[a-zA-Z'-‘Ãâå\s]{1,40}
...
using System.Text.RegularExpressions;
...
Regex.IsMatch(s, @"^[a-zA-Z'-‘Ãâå\s]{1,40}$" )
...
Generally most input validation should be pessimistic and allow only input that consists entirely of approved characters. In this way, may user encounter with some restrictions but it helps to protect against malicious input such as SQL injection attacks.

[a-zA-Z'-‘Ãâå\s]{1,40}
...
using System.Text.RegularExpressions;
...
Regex.IsMatch(s, @"^[a-zA-Z'-‘Ãâå\s]{1,40}$" )
...
Generally most input validation should be pessimistic and allow only input that consists entirely of approved characters. In this way, may user encounter with some restrictions but it helps to protect against malicious input such as SQL injection attacks.
Regex - String input validation by regular expressions
Sunday, March 29, 2009
Regular Experessions - Part 2 - WildCards
To match repeated characters there are symbols for regular expression that makes the job possible.
Metacharacter Description Equivalent
------------- ----------- ----------
* Matches the preceding character or {0,}
subexpression zero or more times.
+ Matches the preceding character or {1,}
subexpression one or more times.
? Matches the preceding character or {0,1}
subexpression zero or one time.
{n} Matches the preceding character or
subexpression exactly n times. n>0
{n,m} Matches the preceding character or
subexpression at least n and at most
m times. (n > 0), (m > 0), (n <= m)
? (nongreedy) - A nongreedy pattern matches as
little of the searched string as
possible.
- A greedy pattern (default) matches
as much of the searched string as
possible.
? follows any other quantifiers [*,
+, ?, {n}, {n,m}], makes a nongreedy
pattern. Example: in string "aaaaa",
a+? matches a single 'a', but a+
matches all a's.
a|b Matches either a or b. a|book matches
a or book and (a|b)ook matches aook
or book.
[abcd] A character set, matches any one of
the enclosed characters. Example: [ab]
matches 'a' in "Plane".
[a-z] A range of characters. Example: to match
all alphanumeric characters [a-zA-Z0-9].

Metacharacter Description Equivalent
------------- ----------- ----------
* Matches the preceding character or {0,}
subexpression zero or more times.
+ Matches the preceding character or {1,}
subexpression one or more times.
? Matches the preceding character or {0,1}
subexpression zero or one time.
{n} Matches the preceding character or
subexpression exactly n times. n>0
{n,m} Matches the preceding character or
subexpression at least n and at most
m times. (n > 0), (m > 0), (n <= m)
? (nongreedy) - A nongreedy pattern matches as
little of the searched string as
possible.
- A greedy pattern (default) matches
as much of the searched string as
possible.
? follows any other quantifiers [*,
+, ?, {n}, {n,m}], makes a nongreedy
pattern. Example: in string "aaaaa",
a+? matches a single 'a', but a+
matches all a's.
a|b Matches either a or b. a|book matches
a or book and (a|b)ook matches aook
or book.
[abcd] A character set, matches any one of
the enclosed characters. Example: [ab]
matches 'a' in "Plane".
[a-z] A range of characters. Example: to match
all alphanumeric characters [a-zA-Z0-9].
Regular Experessions - Part 2 - WildCards
Friday, March 27, 2009
Regular Experessions - Part 1 - Regex (System.Text.RegularExpressions)
A regular expression is a set of characters that can be compared to a string to determine whether it meets specified format requirements. For validation purposes and to check user inputs, regular expressions are an extremely efficient way.
To use regular expression class and related methods, you need to add its namespace:
using System.Text.RegularExpressions;
...
if (txtRegExp.Text == String.Empty) return;
if (Regex.IsMatch(txtRegExp.Text, @"^\d{3}$"))
MessageBox.Show(String.Format("This strings '{0}' contains 3 digits.",
txtRegExp.Text));
...
In above example regular expression string is "^\d{3}$",
- Leading Caret (^) represent the start of string.
- $ sign represents the end of the string.
- \d means numeric digits.
- {3} indicates three sequential numeric digits.
If you omit leading caret ^ the regular expression would be "\d{3}$" and the expression still matching any string which ending with three digit numbers.

To use regular expression class and related methods, you need to add its namespace:
using System.Text.RegularExpressions;
...
if (txtRegExp.Text == String.Empty) return;
if (Regex.IsMatch(txtRegExp.Text, @"^\d{3}$"))
MessageBox.Show(String.Format("This strings '{0}' contains 3 digits.",
txtRegExp.Text));
...
In above example regular expression string is "^\d{3}$",
- Leading Caret (^) represent the start of string.
- $ sign represents the end of the string.
- \d means numeric digits.
- {3} indicates three sequential numeric digits.
If you omit leading caret ^ the regular expression would be "\d{3}$" and the expression still matching any string which ending with three digit numbers.
Regular Experessions - Part 1 - Regex (System.Text.RegularExpressions)
Subscribe to:
Posts (Atom)