Skip to content

Instantly share code, notes, and snippets.

@Zenexer
Last active May 3, 2020 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zenexer/a04a2bdec5ee630bbb56af5594bc2685 to your computer and use it in GitHub Desktop.
Save Zenexer/a04a2bdec5ee630bbb56af5594bc2685 to your computer and use it in GitHub Desktop.
{
(?#
# Adapted for PHP by Paul Buonopane
# Based heavily on the following works:
# - https://manishearth.github.io/blog/2018/02/15/picking-apart-the-crashing-ios-string/
# - https://github.com/hackbunny/viramarama
#
# This PHP regex will match any string that contains Indic character
# combinations known to crash many iOS applications as of 11.2.5 and certain
# macOS applications as of 10.13.3.
#
# IMPORTANT: This will only work if you use the `x` and `u` modifiers.
# Example: "/regex-goes-here/xu"
#
# COMPATIBILITY: While PHP does use PCRE, the `u` modifier isn't technically
# Perl-compatible. For this to work without the `u` modifier,
# the regex would need to be adapted to use | instead of [],
# as all of these characters are multibyte in all popular web
# encodings, e.g. UTF-8.
#
# Tracked By: rdar://37458268
# https://openradar.appspot.com/37458268
# Date Originated: 2018-02-12
# CVE ID: Unknown as of writing
#)
(?(DEFINE)
(?<zwnj> ‌(?# You can't see me, but I'm here!))
(?<devanagari_virama> ्)
(?<devanagari_consonants> [कखगघङहचछजझञयशटठडढणरषतथदधनलसपफबभमव])
(?<devanagari_sj_consonants> [र])
(?<devanagari_pj_pairs> र(?&devanagari_virama)र)
(?<devanagari_vowels> [ऺऻािीुूृॄॅॆेैॉॊोौॎॏॕॖॗॢॣ])
(?<bengali_virama> ্)
(?<bengali_consonants> [কখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরৰলৱশষসহ])
(?<bengali_sj_consonants> [যর])
(?<bengali_pj_pairs> [রৰ](?&bengali_virama)র)
(?<bengali_vowels> [ািীুূৃৄেৈৢৣ])
(?<telugu_virama> ్)
(?<telugu_consonants> [కఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరలవళశషసహఱ])
(?<telugu_sj_consonants> (?&telugu_consonants))
(?<telugu_vowels> [ాిీుూృౄెేొోౌౢౣ])
)
(?!(?&devanagari_pj_pairs))
(?&devanagari_consonants)
(?&devanagari_virama)
(?&devanagari_sj_consonants)
(?&zwnj)
(?&devanagari_vowels)
|
(?!(?&bengali_pj_pairs))
(?&bengali_consonants)
(?&bengali_virama)
(?&bengali_sj_consonants)
(?&zwnj)
(?&bengali_vowels)
|
(?&telugu_consonants)
(?&telugu_virama)
(?&telugu_sj_consonants)
(?&zwnj)
(?&telugu_vowels)
(?#
# The license for the work on which this regex is based is provided below, with an
# additional note regarding adaptation.
#
# Copyright 2018 hackbunny <hackbunny@gmail.com>
# Adapted for PHP by Paul Buonopane
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files [the "Software"], to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#)
}xu
{(?(DEFINE)(?<zwnj>‌)(?<devanagari_virama>्)(?<devanagari_consonants>[कखगघङहचछजझञयशटठडढणरषतथदधनलसपफबभमव])(?<devanagari_sj_consonants>[र])(?<devanagari_pj_pairs>र(?&devanagari_virama)र)(?<devanagari_vowels>[ऺऻािीुूृॄॅॆेैॉॊोौॎॏॕॖॗॢॣ])(?<bengali_virama>্)(?<bengali_consonants>[কখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরৰলৱশষসহ])(?<bengali_sj_consonants>[যর])(?<bengali_pj_pairs>[রৰ](?&bengali_virama)র)(?<bengali_vowels>[ািীুূৃৄেৈৢৣ])(?<telugu_virama>్)(?<telugu_consonants>[కఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరలవళశషసహఱ])(?<telugu_sj_consonants>(?&telugu_consonants))(?<telugu_vowels>[ాిీుూృౄెేొోౌౢౣ]))(?!(?&devanagari_pj_pairs))(?&devanagari_consonants)(?&devanagari_virama)(?&devanagari_sj_consonants)(?&zwnj)(?&devanagari_vowels)|(?!(?&bengali_pj_pairs))(?&bengali_consonants)(?&bengali_virama)(?&bengali_sj_consonants)(?&zwnj)(?&bengali_vowels)|(?&telugu_consonants)(?&telugu_virama)(?&telugu_sj_consonants)(?&zwnj)(?&telugu_vowels)}u
স্র‌ু
జ్ఞ‌ా
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment