{"id":16389603,"url":"https://github.com/zadean/xs_regex","last_synced_at":"2025-10-28T21:43:37.010Z","repository":{"id":57557790,"uuid":"140725521","full_name":"zadean/xs_regex","owner":"zadean","description":"XML Schema Regex for Erlang","archived":false,"fork":false,"pushed_at":"2022-01-05T20:52:12.000Z","size":342,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T19:08:56.866Z","etag":null,"topics":["erlang","regex","regular-expression","xml","xml-schema","xpath","xquery"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zadean.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-12T14:37:11.000Z","updated_at":"2022-01-05T20:52:15.000Z","dependencies_parsed_at":"2022-08-28T11:41:44.189Z","dependency_job_id":null,"html_url":"https://github.com/zadean/xs_regex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadean%2Fxs_regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadean%2Fxs_regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadean%2Fxs_regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadean%2Fxs_regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zadean","download_url":"https://codeload.github.com/zadean/xs_regex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238328490,"owners_count":19453833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erlang","regex","regular-expression","xml","xml-schema","xpath","xquery"],"created_at":"2024-10-11T04:33:45.237Z","updated_at":"2025-10-26T13:30:38.269Z","avatar_url":"https://github.com/zadean.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"xs_regex\n=====\n\nAn OTP library that translates XML Schema regular expressions (described [here](https://www.w3.org/TR/xmlschema-2/#regexs)) into the Erlang flavor.\n\n### XML Schema Features\n* Character classes (including the shorthands \\i, \\I, \\c, \\C, \\d, \\D, \\w, \\W).\n* **Character class subtraction** ([a-z-[s-u]] returns [a-rv-z]).\n* Alternation and groups.\n* Greedy quantifiers\n* Unicode properties and language blocks.\n\n### XPath / XQuery Features\n* Anchors (\"^\", \"$\").\n* Lazy quantifiers.\n* Back-references (also in replacement text using $1 notation).\n* Capturing groups.\n* i, s, m, x, and q flags\n\n#### Flags\n* s - \"dot-all\", \".\" matches newline\n* m - Multi-line mode\n* i - Case-insensitive\n* x - \"extended\", whitespaces outside character classes are removed\n* q - All characters are treated as literals (s, m, and x have no effect)\n\n#### Usage\n\n```erlang\n1\u003e xs_regex:translate(\"[a-z-[s-u]]\").\n{ok,\"[a-rv-z]\"}\n```\n\nThe `xs_regex:compile/2` function returns a boolean stating if the pattern matches the empty string, and the compiled pattern. \n\n```erlang\n1\u003e xs_regex:compile(\"[a-z-[s-u]]\", \"ix\").\n{false,{re_pattern,0,1,1,\n                   \u003c\u003c69,82,67,80,112,0,0,0,9,8,64,36,1,0,0,0,255,255,255,\n                     255,255,255,...\u003e\u003e}}\n```\n\n\"$1\" notation is transformed to \"\\g{1}\" notation.\n\n```erlang\n1\u003e Pattern = \"(a)|(b)|(c)|(d)|(e)|(f)|(g)|(h)|(i)|(j)\".\n\"(a)|(b)|(c)|(d)|(e)|(f)|(g)|(h)|(i)|(j)\"\n2\u003e {_, MP} = xs_regex:compile(Pattern, \"\").\n{false,{re_pattern,10,1,1,\n                   \u003c\u003c69,82,67,80,198,0,0,0,32,8,64,36,1,0,0,0,255,255,255,\n                     255,255,255,...\u003e\u003e}}\n3\u003e {ok, Depth} = xs_regex:get_depth(Pattern).\n{ok,10}\n4\u003e {ok, Repl} = xs_regex:transform_replace(\"$1|$4\",Depth).\n{ok,\"\\\\g{1}|\\\\g{4}\"}\n5\u003e re:replace(\"abcdefghijk\", MP, Repl, [{return,list},global]).\n\"a||||d||||||k\"\n```\n\nArabic decimal digits:\n\n```erlang\n2\u003e xs_regex:translate(\"[\\\\p{IsArabic}-[\\\\P{Nd}]]\").\n{ok,\"[\\\\x{660}-\\\\x{669}\\\\x{6F0}-\\\\x{6F9}]\"}\n```\n\nOpening XML tag:\n\n```erlang\n3\u003e xs_regex:translate(\"\u003c\\\\i\\\\c*\u003e\").\n{ok,\"\u003c(?-i:[\\\\x{3A}A-Z\\\\x{5F}a-z\\\\x{C0}-\\\\x{D6}\\\\x{D8}-\\\\x{F6}\\\\x{F8}-\\\\x{2FF}\\\\x{370}-\\\\x{37D}\\\\x{37F}-\\\\x{1FFF}\\\\x{200C}-\\\\x{200D}\\\\x{2070}-\\\\x{218F}\\\\x{2C00}-\\\\x{2FEF}\\\\x{3001}-\\\\x{D7FF}\\\\x{F900}-\\\\x{FDCF}\\\\x{FDF0}-\\\\x{FFFD}\\\\x{10000}-\\\\x{EFFFF}])(?-i:[\\\\x{2D}-\\\\x{2E}0-\\\\x{3A}A-Z\\\\x{5F}a-z\\\\x{B7}\\\\x{C0}-\\\\x{D6}\\\\x{D8}-\\\\x{F6}\\\\x{F8}-\\\\x{37D}\\\\x{37F}-\\\\x{1FFF}\\\\x{200C}-\\\\x{200D}\\\\x{203F}-\\\\x{2040}\\\\x{2070}-\\\\x{218F}\\\\x{2C00}-\\\\x{2FEF}\\\\x{3001}-\\\\x{D7FF}\\\\x{F900}-\\\\x{FDCF}\\\\x{FDF0}-\\\\x{FFFD}\\\\x{10000}-\\\\x{EFFFF}])*\u003e\"}\n```\n\nUpper-case Greek:\n\n```erlang\n4\u003e xs_regex:translate(\"^(?:[\\\\p{IsGreek}-[\\\\P{Lu}]]+)$\").\n{ok,\"^(?:[\\\\x{370}\\\\x{372}\\\\x{376}\\\\x{37F}-\\\\x{383}\\\\x{386}\\\\x{388}-\\\\x{38F}\\\\x{391}-\\\\x{3AB}\\\\x{3CF}\\\\x{3D2}-\\\\x{3D4}\\\\x{3D8}\\\\x{3DA}\\\\x{3DC}\\\\x{3DE}\\\\x{3E0}\\\\x{3E2}\\\\x{3E4}\\\\x{3E6}\\\\x{3E8}\\\\x{3EA}\\\\x{3EC}\\\\x{3EE}\\\\x{3F4}\\\\x{3F7}\\\\x{3F9}-\\\\x{3FA}\\\\x{3FD}-\\\\x{3FF}]+)$\"}\n```\n\nUsing non-ascii codepoints in a regex:\n\n```erlang\n5\u003e {ok,R} = xs_regex:normalize(\"^what(?:[\u0026#50806;-\u0026#50809;])s\\\\sthat$\").\n{ok,[94,119,104,97,116,40,63,58,91,50806,45,50809,93,41,115,\n     92,115,116,104,97,116,36]}\n6\u003e xs_regex:translate(R).\n{ok,\"^what(?:[\\\\x{C676}-\\\\x{C679}])s(?-i:[\\\\x{9}\\\\x{A}\\\\x{D}\\\\x{20}])that$\"}\n\n7\u003e {ok,R1} = xs_regex:normalize(\"^what(?:[\u0026#xABC0;-\u0026#xABCF;])s\\\\sthis$\").\n{ok,[94,119,104,97,116,40,63,58,91,43968,45,43983,93,41,115,\n     92,115,116,104,105,115,36]}\n8\u003e xs_regex:translate(R1).\n{ok,\"^what(?:[\\\\x{ABC0}-\\\\x{ABCF}])s(?-i:[\\\\x{9}\\\\x{A}\\\\x{D}\\\\x{20}])this$\"}\n```\n\nBuild\n-----\n\n    $ rebar3 compile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzadean%2Fxs_regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzadean%2Fxs_regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzadean%2Fxs_regex/lists"}