From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search
(creation)
 
(expanded, unstubbed, floatingtoc, additional examples)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{stub}}
{{Header Nav|game=StrategyWiki:Guide}}
{{Header Nav|game=StrategyWiki:Guide}}
{{wikipedia|Regular expression}}
{{floatingtoc|left}}
Regular expressions, often referred to as a regex or regexp, plural regexes or regexps, are used to help find changes that need to be replaced and to replace them.


Regular expressions, often referred to as a regex, plural regexes, are used to help find changes that need to be replaced and to replace them.
{{-}}
 
==Tools==
To use a regular expression you will have to have find a code base that can run it. The easiest tools to use are:
To use a regular expression you will have to have find a code base that can run it. The easiest tools to use are:
*Google Chrome extension: [https://chrome.google.com/webstore/detail/search-and-replace/bldchfkhmnkoimaciljpilanilmbnofo Search and Replace 1.2.2]
*Google Chrome extension: [https://chrome.google.com/webstore/detail/search-and-replace/bldchfkhmnkoimaciljpilanilmbnofo Search and Replace 1.2.2]
*TextPad (go to Search >> Replace, or press F8)
*TextPad (go to Search >> Replace, or press F8). Note: TextPad used to use Unix's implementation and syntax, but now uses Perl/JavaScript's.
 
==Syntax differences==
Note that some tools code their regular expression syntax differently. Major differences occur between programming languages and shells; e.g. Unix vs. Perl/JavaScript implementations.
 
Example: a simple parameter definition search in Unix may look like (this matches all characters a-b and 0-9, minimum of 1 time and maximum of 25 times in a single match):
<pre>
\(a-b,0-9)\{1,25\}\)
</pre>
 
In Perl/Javascript syntax it looks like:
<pre>
(a-b,0-9){1,25}
</pre>


;Syntax differences
For example, TextPad makes uses of simplified expressions, such as [:alpha:] to match a-z and A-Z.
Note that some tools code their regular expression syntax differently. For example, TextPad makes uses of simplified expressions, such as [:alpha:] to match a-z and A-Z.


;Uses
==Example uses==
*Adding a hundred file names to a table. See [http://strategywiki.org/w/index.php?title=Animal_Crossing:_New_Leaf/List_of_Fossils&diff=prev&oldid=674718 this example].
*Adding a hundred file names to a table. See [http://strategywiki.org/w/index.php?title=Animal_Crossing:_New_Leaf/List_of_Fossils&diff=prev&oldid=674718 this example].
**Regex used (in TextPad): "| || \([[:alpha:][:blank:]]\{10,20\}\) || \(.\{1,10\}\) Bells" (without quotes).
**Regex used (in old TextPad Unix syntax): <nowiki>"| || \([[:alpha:][:blank:]]\{10,20\}\) || \(.\{1,10\}\) Bells"</nowiki> (without quotes).
*Simplifying all lines with five character or above Pokemon names, and their identification number, in {{t|PokePic}}.
**Regex used (in new Textpad Perl/JavaScript syntax; without quotes): <nowiki>"\|([[:alpha:]]{5,25}) = [[][[]File[:]Pokemon ([0-9]{3})\{\{\{1\}\}\}.png\{\{!\}\}\{\{\{2\|40px\}\}\}\{\{!\}\}\{\{\{3\|none\}\}\}\]\]"</nowiki>


{{Footer Nav|game=StrategyWiki:Guide|prevpage=Advanced tables|nextpage=Templates}}
{{Footer Nav|game=StrategyWiki:Guide|prevpage=Advanced tables|nextpage=Templates}}

Latest revision as of 18:45, 23 November 2014

Regular expressions, often referred to as a regex or regexp, plural regexes or regexps, are used to help find changes that need to be replaced and to replace them.

Tools[edit]

To use a regular expression you will have to have find a code base that can run it. The easiest tools to use are:

  • Google Chrome extension: Search and Replace 1.2.2
  • TextPad (go to Search >> Replace, or press F8). Note: TextPad used to use Unix's implementation and syntax, but now uses Perl/JavaScript's.

Syntax differences[edit]

Note that some tools code their regular expression syntax differently. Major differences occur between programming languages and shells; e.g. Unix vs. Perl/JavaScript implementations.

Example: a simple parameter definition search in Unix may look like (this matches all characters a-b and 0-9, minimum of 1 time and maximum of 25 times in a single match):

\(a-b,0-9)\{1,25\}\)

In Perl/Javascript syntax it looks like:

(a-b,0-9){1,25}

For example, TextPad makes uses of simplified expressions, such as [:alpha:] to match a-z and A-Z.

Example uses[edit]

  • Adding a hundred file names to a table. See this example.
    • Regex used (in old TextPad Unix syntax): "| || \([[:alpha:][:blank:]]\{10,20\}\) || \(.\{1,10\}\) Bells" (without quotes).
  • Simplifying all lines with five character or above Pokemon names, and their identification number, in {{PokePic}}.
    • Regex used (in new Textpad Perl/JavaScript syntax; without quotes): "\|([[:alpha:]]{5,25}) = [[][[]File[:]Pokemon ([0-9]{3})\{\{\{1\}\}\}.png\{\{!\}\}\{\{\{2\|40px\}\}\}\{\{!\}\}\{\{\{3\|none\}\}\}\]\]"