Archive:RegEx tutorial: Difference between revisions
>Gamester17 No edit summary |
>NedBot m (Robot: Changing Category:How To to Category:How-to; cosmetic changes) |
||
Line 15: | Line 15: | ||
=Introduction to Regular Expression= | = Introduction to Regular Expression = | ||
Regular expressions are a tiny, highly specialized programming language. Regular expressions provide tools for developing complex pattern-matching and textual search-and-replace algorithms. Any PHP, Perl, egrep, awk, or sed developer will tell you that regular expressions are one of the most powerful utilities available for manipulating text and data. By creating patterns to match specific strings, a developer has total control over searching, extracting, or replacing data. In short, to master regular expressions is to master your data. | Regular expressions are a tiny, highly specialized programming language. Regular expressions provide tools for developing complex pattern-matching and textual search-and-replace algorithms. Any PHP, Perl, egrep, awk, or sed developer will tell you that regular expressions are one of the most powerful utilities available for manipulating text and data. By creating patterns to match specific strings, a developer has total control over searching, extracting, or replacing data. In short, to master regular expressions is to master your data. | ||
A regular expression is a series of characters that define a pattern. The pattern is then compared to a target string to see whether there are any matches to the pattern in the target string. | A regular expression is a series of characters that define a pattern. The pattern is then compared to a target string to see whether there are any matches to the pattern in the target string. | ||
==Patterns== | == Patterns == | ||
Regular expressions are almost another language by itself. A pattern defines the criteria to search for within a string. Regular expressions can be as simple as plain text, or use a unique language consisting of special characters and modifiers to build these patterns. | Regular expressions are almost another language by itself. A pattern defines the criteria to search for within a string. Regular expressions can be as simple as plain text, or use a unique language consisting of special characters and modifiers to build these patterns. | ||
===Regex Examples (PCRE)=== | === Regex Examples (PCRE) === | ||
====Regular expression examples for decimals input==== | ==== Regular expression examples for decimals input ==== | ||
Positive Integers --- ^\d+$ | Positive Integers --- ^\d+$ | ||
Negative Integers --- ^-\d+$ | Negative Integers --- ^-\d+$ | ||
Line 37: | Line 37: | ||
IP v4 --- ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$ | IP v4 --- ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$ | ||
====Regular expression examples for Alphabetic input==== | ==== Regular expression examples for Alphabetic input ==== | ||
Personal Name --- ^[\w\.\']{2,}([\s][\w\.\']{2,})+$ | Personal Name --- ^[\w\.\']{2,}([\s][\w\.\']{2,})+$ | ||
Username --- ^[\w\d\_\.]{4,}$ | Username --- ^[\w\d\_\.]{4,}$ | ||
Line 45: | Line 45: | ||
domain --- ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$ | domain --- ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$ | ||
====Other regular expressions==== | ==== Other regular expressions ==== | ||
Match no input --- ^$ | Match no input --- ^$ | ||
Match blank input --- ^\s[\t]*$ | Match blank input --- ^\s[\t]*$ | ||
Line 52: | Line 52: | ||
==Third-party tools and utilities== | == Third-party tools and utilities == | ||
Third-party tools and utilities can help you write or confirm and verify your written regexs. | Third-party tools and utilities can help you write or confirm and verify your written regexs. | ||
* [http://www.regextester.com REGex TESTER] - webbased tested | * [http://www.regextester.com REGex TESTER] - webbased tested | ||
Line 59: | Line 59: | ||
* [http://macromates.com TextMate for Mac OSX] | * [http://macromates.com TextMate for Mac OSX] | ||
[[Category:How-to|Scraper]] | |||
[[Category:Development]] | |||
[[ | [[Category:Inner Workings]] | ||
[[ | [[Category:Scraper]] | ||
[[ | [[Category:Python]] | ||
[[ | |||
[[ |
Revision as of 22:39, 11 September 2011
Template:XBMC faq toc Inline This is meant to with your help become a general tutorial for using Regular Expression (commonly referred to as "RegEx" or "RegExp"), meant to be a more in depth guide to using XBMC, 'RegEx for dummies' so to speak.
Feel free to add anything to this guide.
These are a bunch of links to other RegEx tutorial which we can borrow information from for this guide:
- Essential Guide To Regular Expressions: Tools and Tutorials
- http://en.wikipedia.org/wiki/Regex
- http://www.english.uga.edu/humcomp/perl/regex2a.html
- http://www.regular-expressions.info/tutorial.html
- http://www.codeproject.com/dotnet/RegexTutorial.asp
- http://forum.xbmc.org/showthread.php?t=25349
- http://www.regextester.com (Regular Expression Testing)
Introduction to Regular Expression
Regular expressions are a tiny, highly specialized programming language. Regular expressions provide tools for developing complex pattern-matching and textual search-and-replace algorithms. Any PHP, Perl, egrep, awk, or sed developer will tell you that regular expressions are one of the most powerful utilities available for manipulating text and data. By creating patterns to match specific strings, a developer has total control over searching, extracting, or replacing data. In short, to master regular expressions is to master your data.
A regular expression is a series of characters that define a pattern. The pattern is then compared to a target string to see whether there are any matches to the pattern in the target string.
Patterns
Regular expressions are almost another language by itself. A pattern defines the criteria to search for within a string. Regular expressions can be as simple as plain text, or use a unique language consisting of special characters and modifiers to build these patterns.
Regex Examples (PCRE)
Regular expression examples for decimals input
Positive Integers --- ^\d+$ Negative Integers --- ^-\d+$ Integer --- ^-{0,1}\d+$ Positive Number --- ^\d*\.{0,1}\d+$ Negative Number --- ^-\d*\.{0,1}\d+$ Positive Number or Negative Number - ^-{0,1}\d*\.{0,1}\d+$ Phone number --- ^\+?[\d\s]{3,}$ Phone with code --- ^\+?[\d\s]+\(?[\d\s]{10,}$ Year 1900-2099 --- ^(19|20)[\d]{2,2}$ Date (dd mm yyyy, d/m/yyyy, etc.) --- ^([1-9]|0[1-9]|[12][0-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$ IP v4 --- ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$
Regular expression examples for Alphabetic input
Personal Name --- ^[\w\.\']{2,}([\s][\w\.\']{2,})+$ Username --- ^[\w\d\_\.]{4,}$ Password at least 6 symbols --- ^.{6,}$ Password or empty input --- ^.{6,}$|^$ email --- ^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$ domain --- ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
Other regular expressions
Match no input --- ^$ Match blank input --- ^\s[\t]*$ Match New line --- [\r\n]|$
Third-party tools and utilities
Third-party tools and utilities can help you write or confirm and verify your written regexs.
- REGex TESTER - webbased tested
- Regular Expression Tester - another webbased tested
- Notepad++ for Windows
- TextMate for Mac OSX