{"id":13576814,"url":"https://github.com/kmarius/jsregexp","last_synced_at":"2025-04-05T08:33:27.936Z","repository":{"id":44417293,"uuid":"398913775","full_name":"kmarius/jsregexp","owner":"kmarius","description":"JavaScript regular expressions for Lua","archived":false,"fork":false,"pushed_at":"2024-10-27T18:05:40.000Z","size":283,"stargazers_count":30,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-05T13:42:25.769Z","etag":null,"topics":["javascript","lua","regex","regexp"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kmarius.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-22T22:27:32.000Z","updated_at":"2024-11-05T03:35:43.000Z","dependencies_parsed_at":"2024-06-27T09:40:32.029Z","dependency_job_id":"c1db9a44-7d0e-458c-a668-4de437651106","html_url":"https://github.com/kmarius/jsregexp","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmarius%2Fjsregexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmarius%2Fjsregexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmarius%2Fjsregexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmarius%2Fjsregexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kmarius","download_url":"https://codeload.github.com/kmarius/jsregexp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312065,"owners_count":20918340,"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":["javascript","lua","regex","regexp"],"created_at":"2024-08-01T15:01:14.511Z","updated_at":"2025-04-05T08:33:27.923Z","avatar_url":"https://github.com/kmarius.png","language":"C","readme":"# jsregexp\n\nProvides ECMAScript regular expressions for Lua 5.1, 5.2, 5.3, 5.4 and LuaJit. Uses `libregexp` from Fabrice Bellard's [QuickJS](https://bellard.org/quickjs/).\n\n## Installation\n\nTo install `jsregexp` globally with [luarocks](https://luarocks.org/modules/kmarius/jsregexp),\nrun\n```bash\nsudo luarocks install jsregexp\n```\nTo install `jsregexp` for a different lua version (in this case Lua5.1 or LuaJit), run\n```bash\nsudo luarocks --lua-version 5.1 install jsregexp\n```\n\nTo install `jsregexp` locally for your user, run\n\n```bash\nluarocks --local --lua-version 5.1 install jsregexp\n```\n\nThis will place the compiled module in `$HOME/.luarocks/lib/lua/5.1` so `$HOME/.luarocks/lib/lua/5.1/?.so` needs to be added to `package.cpath`.\n\nSimply running `make` in this project's root will compile the module `jsregexp.so` (tested on linux only).\n\n## Usage\nThis module provides two functions\n```lua\njsregexp.compile(regex, flags?)\njsregexp.compile_safe(regex, flags?)\n```\nthat take an ECMAScript regular expression as a string and an optional string of flags, most notably\n\n- `\"d\"` provide tables with begin/end indices of match groups in match objects\n- `\"i\"`: case insensitive search\n- `\"g\"`: match globally\n- `\"n\"`: enables named groups (not present in JavaScript, needs to be enabled manually if needed)\n- `\"u\"`: utf-16 support if detected in the pattern string (**implicity set**)\n\nThe complete list of flags can be found in the [JavaScript reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#parameters).\n\nOn success, `compile` and `compile_safe` return a RegExp object. On failure, `compile` throws an error while `compile_save` returns `nil` and an error message.\n\n### RegExp object\n\nEach RegExp object `re` has the following fields\n```lua\nre.last_index   -- the position at wchich the next match will be searched in re:exec or re:test (see notes below)\nre.source       -- the regexp string\nre.flags        -- a string representing the active flags\nre.dot_all      -- is the dod_all flag set?\nre.global       -- is the global flag set?\nre.has_indices  -- is the indices flag set?\nre.ignore_case  -- is the ignore_case flag set?\nre.multiline    -- is the multiline flag set?\nre.sticky       -- is the sticky flag set?\nre.unicode      -- is the unicode flag set?\n```\nCalling `tostring` on a RegExp object returns representation in the form of `\"/\u003csource\u003e/\u003cflags\u003e\"`.\n\nThe RegExp object `re` has the following methods corresponding to JavaScript regular expressions:\n```lua\nre:exec(str)                      -- returns the next match of re in str (see notes below)\nre:test(str)                      -- returns true if the regex matches str (see notes below)\nre:match(str)                     -- returns a list of all matches or nil if no match\nre:match_all(str)                 -- returns a closure that repeatedly calls re:exec, to be used in for-loops\nre:match_all_list(str)            -- returns a list of all matches\nre:search(str)                    -- returns the 1-based index of the first match of re in str, or -1 if no match\nre:split(str, limit?)             -- splits str at re, at most limit times\nre:replace(str, replacement)      -- relplace the first match of re in str by replacement (all, if global)\nre:replace_all(str, replacement)  -- relplace each match of re in str by replacement\n```\nFor the documentation of the behaviour of each of these functions, see the [JavaScript reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).\n\n**Note:** Each regexp object has a field `last_index` which denotes the position at which the next call to `exec` and `test` searches for the next match.\nAfterwards `last_index` is changed accordingly. If you need to use these methods, you should reset `last_index` to 1.\n\n**Note:** Because the regexp engine used works with UTF16 instead of UTF8, the input string is converted to UTF16 if necessary. Calling `exec` or `test` on\nnon-Ascii strings repeatedly could potentially introduce a large overhead. This conversion only needs to be done once for the `match*` methods, you probably want to use those instead.\n\n\n### Match object\n\nA match object `m` returned by `exec` and the `match*` functions has the following fields:\n```lua\nm[0]             -- the full match\nm[i]             -- match group i\nm.input          -- the input string\nm.capture_count  -- number of capture groups\nm.index          -- start of the capture (1-based)\nm.groups         -- table of the named groups and their content\nm.indices        -- table of begin/end indices of all match groups (if \"d\" flag is set)\nm.indices.groups -- table of named groups and their begin/end indices (if \"d\" flag is set)\n```\nCalling `tostring` on a match object returns the full  match `m[0]`.\n\n## Example\n```lua\nlocal jsregexp = require(\"jsregexp\")\n\nlocal re, err = jsregexp.compile_safe(\"(\\\\w)\\\\w*\", \"g\")\nif not re then\n\tprint(err)\n\treturn\nend\n\nlocal str = \"Hello World\"\n\nfor match in re:match_all(str) do\n\tprint(match)\n\tfor j, group in ipairs(match) do\n\t\tprint(j, group)\n\tend\nend\n```\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmarius%2Fjsregexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkmarius%2Fjsregexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmarius%2Fjsregexp/lists"}