Symbol |
Meaning |
Example |
Matches |
^ |
Beginning of input text |
^A |
A, Text started with A (Represent to find the first word in the multiline text.) |
$ |
End of the input text |
Z$ |
Z, Text ended with Z (Represent to find the last word in the multiline text.) |
. |
Any single character except new line character (\n). |
Li.e |
Line, Lime |
* |
Preceding character may be repeated 0 or more times. |
is*e |
ie, ise, isse, issse, isssse … |
+ |
Preceding character may be repeated 1 or more times. |
is+e |
ise, isse, issse, isssse … |
? |
Preceding character may be repeated 0 or 1 time. |
is?e |
ie, ise |
\s |
Any whitespace character |
\sar |
[Space]ar, [new line\n]ar [tab\t]ar |
\S |
Any character other than whitespace character. |
\Sar |
Ear, jar, war, var .. |
\b |
Any word boundary (either beginning or end) characters specified |
ion\b |
Nation, solution, addition … |
\B |
Any word with specified characters in any position except (boundary) beginning and end. |
\Bcc |
Success, access |
\d |
Decimal characters |
\d{3} |
3 digit |
\D |
Non -Decimal characters |
(\D)* |
Abcdefgh |
-
Regularexpression uses to validate the input data in the specific format. In .Net web pages validate the input text using regular expression validator control (System.Web.UI.WebControls.RegularExpressionValidator).
Data |
Pattern |
Example |
|
\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* |
thirumalganesh@hotmail.com |
US telephone |
((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4} |
(656) 555-7419 |
Singapore telephone with country code |
((\(\d{2}\) ?))?\d{8} |
(65) 65557419 |
Web address |
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? |
|
Numerical input only |
(\d{1})* |
123456789 |
Non numerical input |
(\D)* |
abcdefgh |
-
uses to search the words in specific pattern from the contents.
using System; using System.Text.RegularExpressions; namespace RegularExpression { class Program { public static string input = @"I have been in software industry since 1999 holding various roles and responsibilities as developer, tester and support team member from small scale industry to industry giant. And having experience and expertise with Microsoft technologies such as VB, SQL Server, C#.Net, Vb.NET, ASP.NET, ADO.NET, Crystal report and Oracle. And involved in requirement study, design, development, testing, implementation, documentation , training and support in my carrier."; static void Main(string[] args) { //Some example for the pattern to search the word from the input text //@"\S*\Bcr\S*" Microsoft //@"\bcr\S*" Crystal //@"\S*\bvb\S*" Vb, vb.net //@"\S*Net\b*" C#.Net, VB.Net, ASP.Net, //@"\S*ier.$" carrier. (last word in the input string) //@"^i\S*" I (First word in the input string) MatchCollection Matches = findTheMatches(@"^i\S*"); foreach (Match match in Matches) { Console.WriteLine(match); } Console.WriteLine(input); Console.ReadLine(); } static MatchCollection findTheMatches(string Pattern) { return Regex.Matches(input, Pattern, RegexOptions.IgnoreCase); } } } |
-
delete the repeated word from the contents using specific pattern
-
convert the character case in the word using specific pattern.
-
make sure the character case in the word.