User:Kjhf/Sandbox/Regex

From Inkipedia, the Splatoon wiki
Jump to navigation Jump to search

Use on: http://regexr.com/

User:KJ Bot uses these Regexes. If you see any bugs, please let me know.

Regexes

Next Category (not link)

new Regex(@"\[\[Category:[^\]]*\]\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Next Category (link)

new Regex(@"\[\[:Category:[^\]]*\]\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Link

new Regex(@"\[\[[^\]]*\]\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Template

new Regex(@"{{[^}]*}}", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Digits

new Regex(@"[\d]+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Table Row (|-)

new Regex(@"(\|-)+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Header

new Regex(@"^[=]+[^=]*[=]+", RegexOptions.IgnoreCase | RegexOptions.Multiline);
return match.TrimStart('=').TrimEnd('=').Trim(); // trims = and whitespace

Numeric Only File

new Regex(@"^(File:|Image:)?[\d.]+[A-z]*$", RegexOptions.IgnoreCase); // not multiline

Bad File Name

new Regex(@"^(File:|Image:)?(Splatoon)?((Screen)*\W?(shot)*)?([\d. -])+[A-z]*$", RegexOptions.IgnoreCase); // not multiline

Redirect

new Regex(@"^(#REDIRECT)+[\W]*[\[\]\w]+", RegexOptions.IgnoreCase); // NOT multiline - redirects must be a start of article.

Is Candidate For Deletion

new Regex(@"{{\s*(Template:)*(Delete)+[^}]*}}", RegexOptions.IgnoreCase | RegexOptions.Multiline);

Is Inside Article Name

   {
     int offset = index;
     while (offset-- > 0)
     {
       switch (text[offset])
       {
         case '|':
         case ']':
         case '}':
           return false;
         case ':':
         case '[':
         case '{':
           return true;
       }
     }
     return false;
   }


Test page

Latest.png
7987
1.png
1.2.jpg
1.a.jpg
splatoon1.png
something.jpg
blaster1.jpeg
AmiiboTouchdown.png
Booya-basex2.jpg
195.png
Splat Charger.jpeg
Splatoonweapon.png
Latest.png
File:7987
Image:1.png
File:1.2.jpg
File:1.a.jpg
File:splatoon1.png
File:something.jpg
File:blaster1.jpeg
File:AmiiboTouchdown.png
File:Booya-basex2.jpg
File:195.png
File:Splat Charger.jpeg
File:Splatoonweapon.png  
Example Wiki template:
{{-}}
<center>
{{NewNav2
| name  = CharBox
| title = Weapons
| group1 = '''{{color-link|Main Weapon|white|Main}}'''
| sublist1= [[Splattershot Jr.]]<sup>([[Custom Splattershot Jr.|Custom]])</sup>{{·}}[[Splattershot]]<sup>([[Tentatek Splattershot|Tentatek]])</sup>{{·}}[[N-Zap '85]]{{·}}[[.52 Gal]]<sup>([[.52 Gal Deco|Deco]])</sup>{{·}}[[Splash-o-matic]]{{·}}[[Aerospray MG]]<sup>([[Aerospray RG|RG]])</sup>{{·}}[[Jet Squelcher]]<sup>([[Custom Jet Squelcher|Custom]])</sup>{{·}}[[Blaster]]<sup>([[Custom Blaster|Custom]])</sup>{{·}}[[Splattershot Pro]]<sup>([[Forge Splattershot Pro|Forge]])</sup>{{·}}[[.96 Gal]]{{·}}[[Rapid Blaster]]<sup>([[Rapid Blaster Deco|Deco]])</sup>{{·}}[[Dual Squelcher]]{{·}}[[Hero Shot Replica]]
| sublist2= [[Splat Roller]]<sup>([[Krak-On Splat Roller|Krak-On]])</sup>{{·}}[[Inkbrush]]{{·}}[[Dynamo Roller]]<sup>([[Gold Dynamo Roller|Gold]])</sup>{{·}}[[Hero Roller Replica]]
| sublist3= [[Splat Charger]]<sup>([[Kelp Splat Charger|Kelp]])</sup>{{·}}[[Classic Squiffer]]<sup>([[New Squiffer|New]])</sup>{{·}}[[Splatterscope]]<sup>([[Kelp Splatterscope|Kelp]])</sup>{{·}}[[E-Liter 3K]]{{·}}[[Hero Charger Replica]]
| group2 = '''{{color-link|Sub Weapon|white|Sub}}'''
| list2  = [[Burst Bomb]]{{·}}[[Disruptor]]{{·}}[[Ink Mine]]{{·}}[[Point Sensor]]{{·}}[[Seeker]]{{·}}[[Splat Bomb]]{{·}}[[Splash Wall]]{{·}}[[Sprinkler]]{{·}}[[Squid Beakon]]{{·}}[[Suction Bomb]]
| group3 = '''{{color-link|Special Weapon|white|Special}}'''
| list3  = [[Bubbler]]{{·}}[[Echolocator]]{{·}}[[Inkstrike]]{{·}}[[Inkzooka]]{{·}}[[Killer Wail]]{{·}}[[Kraken]]
}}
|}<includeonly>[[Category:Weapons]]</includeonly>
</center><noinclude>[[Category:List Templates]]</noinclude>
Sample text for testing:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789 +-.,!@#$%^&*();\/|<>"'
12345 -98.7 3.141 .6180 9,000 +42
555.123.4567	+1-(800)-555-2468
foo@demo.net	bar.ba@test.co.uk
www.demo.com	http://foo.co.uk/
http://regexr.com/foo.html?q=bar