Programming Tutorial On The Way

free online programming resource on dotnet, csharp, web related topics

If you have one or more complex regular expressions that may exist in a file outside of your code, you need a way to place comments within the regular expression itself. These comments will aid others in being able to read and maintain your regular expressions later on.
Add comments to the regular expression using the # comment character:
Read the rest of this entry »

Popularity: 5% [?]

Using Common Patterns

You need a quick list from which to choose regular expression patterns that match standard items. These standard items could be a Social Security Number, a zip code, a word containing only characters, an alphanumeric word, an email address, a URL, dates, or one of many other possible items used throughout business applications.

Regular expressions are effective at finding specific information, and they have a wide range of uses. Many applications use them to locate specific information within a larger range of text, as well as to filter out bad input. The filtering action is very useful in tightening the security of an application and preventing an attacker from attempting to use carefully formed input to gain access to a machine on the Internet or a local network. By using a regular expression to allow only good input to be passed to the application, you can reduce the likelihood of many types of attacks, such as SQL injection or cross-site-scripting.
Read the rest of this entry »

Popularity: 3% [?]

This time the article shows you how to find a specific occurrence of a match within a string. For example, you want to find the third occurrence of a word or the second occurrence of a Social Security Number. In addition, you may need to find every third occurrence of a word in a string.
To put it simple, to find a particular occurrence of a match in a string, simply subscript the array returned from Regex.Matches.
Read the rest of this entry »

Popularity: 3% [?]

This article shows how we can use Regular Expression to search a specific character pattern in a string or file that contains multiple lines. When it is found on a line, the entire line is returned, instead of just the matched text. The method use the StreamReader.ReadLine method to obtain each line in a file in which to run a regular expression against.
Read the rest of this entry »

Popularity: 3% [?]

You have either constructed a regular expression dynamically from your code or based on user input. You need to test the validity of this regular expression’s syntax before you actually use it. This article shows the snippet code for the validation, as following: Read the rest of this entry »

Popularity: 3% [?]

Using regular expression, you can split up a string based on a well-defined set of characters. Using the Split method of the Regex class, we can use a regular expression to indicate the types of tokens and separators that we are interested in gathering. This technique works especially well with equations, since the tokens of an equation are well-defined. Read the rest of this entry »

Popularity: 3% [?]

Using the Replace instance method on the Regex class allows for easy replacement of text within a string. The following overloaded Replace methods accept a source string that contains characters or words to be replaced, a matchPattern to match the replaceable text in the source parameter, and a replaceStr string to replace the text matched by matchPattern. In addition there are two parameters, count and startPos, to control the number of replacements allowed and where the replacements start from in the source string, Read the rest of this entry »

Popularity: 3% [?]

You need to find the last pattern match in a string, but you do not want the overhead of finding all matches in a string and having to move to the last match in the collection of matches. Using the RegexOptions.RightToLeft option, the match starts at the end of the string and proceeds toward the beginning. The first found match is the last match in the string. You supply the RegexOptions.RightToLeft constant as an argument to the Match method. Read the rest of this entry »

Popularity: 2% [?]

« Previous Entries