Post Reply 
 
Freshness Rating:
  • 3 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gossamer's Regex Quirkshop
Offline 11-08-2016, 12:07 PM (This reply was last modified: 11-08-2016 06:41 PM by gossamerGadgeteer.)(Edited by gossamerGadgeteer.)
Reply: #9
RE: Gossamer's Regex Quirkshop
(11-08-2016 03:16 AM)AncientE%cursion Wrote:  For one of my OC's quirks, they replace every 'a' with '[A]' and every 'b' with a '[8]'. Thing is, the a replacement can replace the 'A' inside the brackets which I'm wondering if there's any regex solution to this.

Here's [A]n ex[A]mple of the thing I'm t[A]lking [A][8]out.

Also, do you mind explaining what the hell is up with Cronus' regex setup?

Hmm, I'm a bit confused. Why can't you just use a simple replace of a to [A] and b to [8]? If you're also worried about capital letters, then just make sure to put your capital A replace before your lowercase a replace:
Code:
Simple Replacements:
A to [A]
a to [A]
b to [8]
B to [8]
MSPARP does replaces in order, so if you do your lowercase replace before your capital replace, it'll double up your brackets.

And sure! Here's what Cronus' setup is doing:
1. Remove any apostrophes that are between two letters.
2. If there's a v at the start of a word or line, replace it with φ.
3. If there's a V at the start of a word or line, replace it with Á.
4. If there's a v following a word boundary, or a w before a word boundary, replace it with α. (Note: In a word starting with vv, the first one is replaced, making it φv, and then the second v is now replaced here, since φ creates a word boundary - it's not a normal letter or underscore. Also note: a . creates a word boundary.)
5. Replace any remaining w's or v's with φ. (Same symbol as step 2.)
6. Replace α with wv.
7. Replace φ with vw.
8. If there's a V following a word boundary, or a W at the end of a word, replace it with Ά. (Basically the same as step 4, but with capital letters.)
9. Replace any remaining W's or V's with Á. (Same as step 5 but with capital letters.)
10. Replace Ά with WV.
11. Replace Á with VW.
12. Replace B with 8.
13. If there's a vw in a word (not at the front), followed by an s, n, k, l, or t, replace it with wv instead.
14. If there's a VW in a word (not at the front), followed by an S, N, K, L, or T, replace it with WV instead. (Same as 13 but with capital letters.)
15. Remove any periods that are between two letters. (Remember back in step 4? You can put a . before/after a v or w to MANUALLY swap the vw/wv order. Then this step clears out the period.)
16 & 17. Fixes the following four smileys. :D ;D D: D; (*shrug*)

That's a lot of stuff, and most of it has to do with all the special characters. So, why the weird characters? Because if we tried just adding in v's and w's, we'd end up with duplicates. Say we started with a v. Step 1, put a w after a v: vw. Step 2, put a v after a w: vwv. That's too many! So instead, we use special characters as markers. A w should be a wv, so we give it one marker. A v should be a vw, so we give it a different marker. Cronus' quirk isn't quite that simple, but that's the idea.

Now, let's break it down into what it's actually all doing:
1. Remove any apostrophes inside words.
2. Replace B with 8.
3.1. Replace all v's and w's with vw, EXCEPT:
- If the v is the second v in a row at the start of a word. (This part is probably unintentional, and also unlikely to ever come up.)
- If the v has a non-word character before it. (Like a period.)
- If the w is at the end of the word, or has a non-word character after it. (Again, like a period.)
- If the v or w comes directly before s, n, k, l, or t.
3.2. In any of these cases, replace it with a wv instead.
4. Remove any periods inside words.
5. If :d, ;d, d:, or d; shows up, capitalize the d. (The quirk uses lower case, so this is needed to make smileys work.)

Hope this clears things up for you!
Find all replies by this user
Quote this message in a reply
Post Reply 


Messages In This Memo
RE: Gossamer's Regex Quirkshop - Alienoid - 11-07-2016, 12:08 PM
RE: Gossamer's Regex Quirkshop - Fubar - 11-07-2016, 05:13 PM
RE: Gossamer's Regex Quirkshop - gossamerGadgeteer - 11-08-2016 12:07 PM
RE: Gossamer's Regex Quirkshop - Fubar - 11-16-2016, 04:09 PM
RE: Gossamer's Regex Quirkshop - Milomus2 - 11-25-2016, 02:29 PM
RE: Gossamer's Regex Quirkshop - Galtea - 03-02-2018, 02:44 PM
RE: Gossamer's Regex Quirkshop - Galtea - 03-02-2018, 05:51 PM
RE: Gossamer's Regex Quirkshop - nikdun420 - 02-04-2019, 06:49 AM
RE: Gossamer's Regex Quirkshop - nikdun420 - 03-08-2019, 09:11 AM
RE: Gossamer's Regex Quirkshop - Alienoid - 03-02-2019, 09:53 AM
RE: Gossamer's Regex Quirkshop - Alienoid - 03-04-2019, 07:07 PM
RE: Gossamer's Regex Quirkshop - Sir - 07-11-2019, 02:49 AM
RE: Gossamer's Regex Quirkshop - Sir - 07-12-2019, 12:42 AM

Board jump:


User(s) browsing this memo: 1 Guest(s)