Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Example emoticon system that replaces ascii emoticons with unicode emoticons:
- #Replaces (.V.) with (\/) (°,,,°) (\/)
- match [^\b\B]\(\.V\.\)[\b\B$]
- then replace (\/) (°,,,°) (\/)
- #Replaces #-o with (ʘ言ʘ╬)
- match [^\b\B]\#\-o[\b\B$]
- then replace (ʘ言ʘ╬)
- #Replaces B-) or B) with ༼⌐■ل͟■༽
- match [^\b\B]B(?:\-)?\)[\b\B$]
- then replace ༼⌐■ل͟■༽
- #Replaces :disappoint: with ಠ_ಠ
- match [^\b\B]\:disappoint\:[\b\B$]
- then replace ಠ_ಠ
- Explanation of regex:
- "[^\b\B]" matches "^", which is the start of a string or line, "\b", which is a word boundary, or "\B", which is a non-word boundary.
- "[\b\B$]" matches "\b", which is a word boundary, "\B", which is a non-word boundary, or "$", which is the end of a string or line.
- The above two pieces of regex ensure that we don't accidentally match characters that are part of a word.
- We use "\" a lot to escape characters like "." so it doesn't think we're trying to use them as regex. By using "\.", we can search for ".".
- With the sunglasses emoticon, we used "(?:\-)?". This is a passive group that matches the "-" character. The "?" at the end means it will match 0 or 1 of that character, making it optional so we can match both "B-)" and "B)".
Advertisement
Add Comment
Please, Sign In to add comment