{"id":15497175,"url":"https://github.com/jwerle/sregex","last_synced_at":"2025-04-22T21:42:09.822Z","repository":{"id":9015891,"uuid":"10771711","full_name":"jwerle/sregex","owner":"jwerle","description":"Simple string regular expression that exposes matches in defined variables","archived":false,"fork":false,"pushed_at":"2015-09-30T20:57:18.000Z","size":142,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T15:33:35.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"wimagguc/jquery-eu-cookie-law-popup","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwerle.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-18T19:30:13.000Z","updated_at":"2022-07-22T14:38:03.000Z","dependencies_parsed_at":"2022-07-09T22:00:48.217Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/sregex","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/jwerle%2Fsregex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fsregex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fsregex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fsregex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/sregex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250330225,"owners_count":21412947,"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":[],"created_at":"2024-10-02T08:31:26.987Z","updated_at":"2025-04-22T21:42:09.797Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"sregex\n====\n\nsimple string regular expression that exposes matches in defined variables\n\n## install\n\n*node*\n\n```js\n$ npm install sregex\n```\n\n*component*\n\n```js\n$ component install jwerle/sregex\n```\n\n*bower*\n\n```js\nbower install sregex\n```\n\n\n## usage\n\nusing `sregex` is as simple as passing it a string\n\n```js\n\nvar regex = sregex('some string')\n\nregex.test('some string'); // true\nregex.test('some other string'); // false\n```\n\nthe returned `regex` object from `sregex` is an instance of `RegExp` with a `parse()` function attached to it\n\n```js\n\nregex.parse('some string'); // {}\n```\n\nyou can easily define variables within your string `sregex` string and access them from a string with the `parse` function\n\n```js\nvar regex = sregex('my name is :name and i am :age');\nvar values = regex.parse('my name is joe and i am 22');\n\nconsole.log(values.name); // joe\nconsole.log(values.age); // 22\n```\n\nthe `str` argument for `sregex` accepts a string, but it also can have valid regular expression interpolated\n\n```js\nvar regex = sregex('it can accept multiple regular expressions like ([a-zA-Z]+), ([0-9]+), and ([a-z]+)');\nvar values = regex.parse('it can accept multiple regular expressions like foogots, 45, and apple');\n\nconsole.log(values[0]); // foogots\nconsole.log(values[1]); // 45\nconsole.log(values[2]); // apple\n```\n\nit can also accept an instance of `RegExp as input\n\n```js\nvar regex = sregex(/^foo\\s?bar\\s?([a-z]+)/);\nvar values = regex.parse('foo bar noob');\n\nconsole.log(values[0]); // noob\n```\n\n### building a regular expression router\n\nbuilding a router that parses url parameters can be simple as well\n\n```js\nvar http = require('http');\nvar sregex = require('sregex');\n\nhttp.createServer(function (req, res) {\n\tvar regex = sregex('/:resource/:id/:action')\n\n\t// in the browser head to `http://localhost:4000/videos/1234/edit`\n\tconsole.log(regex.parse(req.url)); // { resource: 'videos', id: '1234', action: 'edit' }\n}).listen(4000);\n```\n\n## api\n\n### sregex(str)\n\nconverts a string to regular expression and allows retrieval of defined variables when parsing\n\n* `str` - a string to convert to regular expression\n\n***example***\n\n```js\nvar regex = sregex('/user/:id')\n```\n\n### .parse(str)\n\nparses a given string and returns an object representing the values extracted using the regular expression used to create it\n\n* `str` - a string to parse and extact values from based on regular expression matches\n\n***example***\n\n```js\nvar regex = sregex('/account/:action')\nvar values = regex.parse('/action/edit');\n\nconsole.log(values.action); // edit\n```\n\n\n## license\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fsregex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fsregex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fsregex/lists"}