Archive:RegEx tutorial: Difference between revisions
>NedBot m (Robot: Changing Category:How To to Category:How-to; cosmetic changes) |
m (Karellen moved page RegEx tutorial to Archive:RegEx tutorial without leaving a redirect: Incomplete and of no educational benefit. Better tutorials online.) |
||
(18 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{mininav|[[Development]]|[[Add-on development]]|[[Scrapers]]}} | ||
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 | |||
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 Kodi, 'RegEx for dummies' so to speak. | |||
Feel free to add anything to this guide. | Feel free to add anything to this guide. | ||
Line 7: | Line 8: | ||
* [http://www.smashingmagazine.com/2009/06/01/essential-guide-to-regular-expressions-tools-tutorials-and-resources/ Essential Guide To Regular Expressions: Tools and Tutorials] | * [http://www.smashingmagazine.com/2009/06/01/essential-guide-to-regular-expressions-tools-tutorials-and-resources/ Essential Guide To Regular Expressions: Tools and Tutorials] | ||
* [http://forum.kodi.tv/showthread.php?tid=25349&pid=128866#pid128866 Kodi developer explanation on RegEx] (Regular Expressions Forum topic) | |||
* http://en.wikipedia.org/wiki/Regex | * http://en.wikipedia.org/wiki/Regex | ||
* http://www.regular-expressions.info/tutorial.html | * http://www.regular-expressions.info/tutorial.html | ||
* http://www.codeproject.com/dotnet/RegexTutorial.asp | * http://www.codeproject.com/dotnet/RegexTutorial.asp | ||
Line 50: | Line 49: | ||
Match New line --- [\r\n]|$ | Match New line --- [\r\n]|$ | ||
=== Forum Discussions === | |||
{{forum link2|[[forum:51614|Extra REGEX for TV Show Episode matching]]}} | |||
{{forum link2|[[forum:25349|Regular Expressions]]}} | |||
== 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] - | * [http://www.regextester.com/index2.html REGex TESTER] - web-based tested | ||
* [http://www.quanetic.com/regex.php Regular Expression Tester] - another | * [http://www.quanetic.com/regex.php Regular Expression Tester] - another web-based tested | ||
* [http://notepad-plus.sourceforge.net Notepad++ for Windows] | * [http://notepad-plus.sourceforge.net Notepad++ for Windows] | ||
* [http://macromates.com TextMate for Mac OSX] | * [http://macromates.com TextMate for Mac OSX] | ||
[[Category:How-to | [[Category:How-to]] | ||
[[Category:Development]] | [[Category:Development]] | ||
[[Category:Scraper]] | [[Category:Scraper]] | ||
[[Category:Python]] | [[Category:Python]] |
Latest revision as of 22:26, 28 May 2022
Development | Add-on development | Scrapers | RegEx tutorial |
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 Kodi, '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
- Kodi developer explanation on RegEx (Regular Expressions Forum topic)
- http://en.wikipedia.org/wiki/Regex
- http://www.regular-expressions.info/tutorial.html
- http://www.codeproject.com/dotnet/RegexTutorial.asp
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]|$
Forum Discussions
Extra REGEX for TV Show Episode matching |
Regular Expressions |
Third-party tools and utilities
Third-party tools and utilities can help you write or confirm and verify your written regexs.
- REGex TESTER - web-based tested
- Regular Expression Tester - another web-based tested
- Notepad++ for Windows
- TextMate for Mac OSX