{"id":22199281,"url":"https://github.com/pmarkert/async-regex-replace","last_synced_at":"2025-07-27T02:32:04.723Z","repository":{"id":57147293,"uuid":"37674080","full_name":"pmarkert/async-regex-replace","owner":"pmarkert","description":"node.js library for regex replacements using asynchronous callback functions ","archived":false,"fork":false,"pushed_at":"2017-06-05T17:04:07.000Z","size":10,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T02:41:08.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/pmarkert.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":"2015-06-18T17:26:11.000Z","updated_at":"2019-08-30T16:32:05.000Z","dependencies_parsed_at":"2022-09-05T16:50:21.432Z","dependency_job_id":null,"html_url":"https://github.com/pmarkert/async-regex-replace","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2Fasync-regex-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2Fasync-regex-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2Fasync-regex-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2Fasync-regex-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmarkert","download_url":"https://codeload.github.com/pmarkert/async-regex-replace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227750211,"owners_count":17814129,"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-12-02T15:13:51.853Z","updated_at":"2024-12-02T15:13:55.685Z","avatar_url":"https://github.com/pmarkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-regex-replace\nnode.js library for regex replacements using asynchronous callback functions\n\n\"All I needed\" was a simple function to do string.replace(/regex/, callback_function) so that I could find some matches in a\nstring and then call my own custom function to return the value to be replaced back into the string. Sounds pretty easy right? \nIt is, as long as your callback function is syncrhonous. :)\n\nWhat happens if you need to call an asychronous function to determine the replacement value(s)? \nPerhaps you are using the matched value to lookup the replacement in a database. \n\n## Enter async-regex-replace\n\n\u003c!--@example('./example.js')--\u003e\n``` js\n'use strict';\nvar async_regex_replace = require('async-regex-replace');\n\nasync_regex_replace.replace(/regex/g, \"String with regex to replace\", function(callback, match) {\n  setTimeout(function() {\n    var replacement_value = match.split('').reverse().join('');\n    var err = null;\n    callback(err, replacement_value);\n  }, 1000);\n}, function(err, final_result) {\n  if(err) { console.log(\"Error - \" + err); }\n  else {\n    console.log(final_result);\n    //\u003e String with xeger to replace\n  }\n});\n```\n\u003c!--/@--\u003e\n\nNOTE: In this particular example, the gratuitous use of setTimeout is just to demonstrate the asynchronous functionality in the replacement callback.\n\n### Captured groups\nIf your regex contains capture groups, they will be passed in as extra parameters after the match but before the callback.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmarkert%2Fasync-regex-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmarkert%2Fasync-regex-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmarkert%2Fasync-regex-replace/lists"}