{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/6029","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/6029/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/6029/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/6029/events","html_url":"https://github.com/PowerShell/PowerShell/pull/6029","id":291725657,"number":6029,"title":"Add ScriptBlock substitution overload to -replace operator","user":{"login":"IISResetMe","id":7413755,"avatar_url":"https://avatars3.githubusercontent.com/u/7413755?v=4","gravatar_id":"","url":"https://api.github.com/users/IISResetMe","html_url":"https://github.com/IISResetMe","followers_url":"https://api.github.com/users/IISResetMe/followers","following_url":"https://api.github.com/users/IISResetMe/following{/other_user}","gists_url":"https://api.github.com/users/IISResetMe/gists{/gist_id}","starred_url":"https://api.github.com/users/IISResetMe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IISResetMe/subscriptions","organizations_url":"https://api.github.com/users/IISResetMe/orgs","repos_url":"https://api.github.com/users/IISResetMe/repos","events_url":"https://api.github.com/users/IISResetMe/events{/privacy}","received_events_url":"https://api.github.com/users/IISResetMe/received_events","type":"User","site_admin":false},"labels":[{"id":483158128,"url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Committee-Reviewed","name":"Committee-Reviewed","color":"0e5a16","default":false}],"state":"open","locked":false,"assignee":{"login":"daxian-dbw","id":127450,"avatar_url":"https://avatars2.githubusercontent.com/u/127450?v=4","gravatar_id":"","url":"https://api.github.com/users/daxian-dbw","html_url":"https://github.com/daxian-dbw","followers_url":"https://api.github.com/users/daxian-dbw/followers","following_url":"https://api.github.com/users/daxian-dbw/following{/other_user}","gists_url":"https://api.github.com/users/daxian-dbw/gists{/gist_id}","starred_url":"https://api.github.com/users/daxian-dbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daxian-dbw/subscriptions","organizations_url":"https://api.github.com/users/daxian-dbw/orgs","repos_url":"https://api.github.com/users/daxian-dbw/repos","events_url":"https://api.github.com/users/daxian-dbw/events{/privacy}","received_events_url":"https://api.github.com/users/daxian-dbw/received_events","type":"User","site_admin":false},"assignees":[{"login":"daxian-dbw","id":127450,"avatar_url":"https://avatars2.githubusercontent.com/u/127450?v=4","gravatar_id":"","url":"https://api.github.com/users/daxian-dbw","html_url":"https://github.com/daxian-dbw","followers_url":"https://api.github.com/users/daxian-dbw/followers","following_url":"https://api.github.com/users/daxian-dbw/following{/other_user}","gists_url":"https://api.github.com/users/daxian-dbw/gists{/gist_id}","starred_url":"https://api.github.com/users/daxian-dbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daxian-dbw/subscriptions","organizations_url":"https://api.github.com/users/daxian-dbw/orgs","repos_url":"https://api.github.com/users/daxian-dbw/repos","events_url":"https://api.github.com/users/daxian-dbw/events{/privacy}","received_events_url":"https://api.github.com/users/daxian-dbw/received_events","type":"User","site_admin":false}],"milestone":null,"comments":16,"created_at":"2018-01-25T21:41:51Z","updated_at":"2018-03-13T13:10:23Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/6029","html_url":"https://github.com/PowerShell/PowerShell/pull/6029","diff_url":"https://github.com/PowerShell/PowerShell/pull/6029.diff","patch_url":"https://github.com/PowerShell/PowerShell/pull/6029.patch"},"body":"## PR Summary\r\n\r\nFix #6164.\r\n\r\nThis PR adds rudimentary lambda support to the `-replace` operator:\r\n\r\n    PS C:\\> \"ID 0000123\" -replace \"\\b0+\", {return \" \" * $args[0].Value.Length}\r\n    ID     123\r\n\r\n----\r\n\r\nThe current `-replace` operator implementation has the following syntax:\r\n\r\n    <value> -replace <pattern>[, <substitution>]\r\n\r\nThis (functionally) maps directly onto:\r\n\r\n    Regex.Replace(<value>, <pattern>, <substitution>)\r\n\r\n`Regex.Replace()` already has an overload that supports a [`MatchEvaluator` delegate](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.matchevaluator?view=netframework-4.7.1), which in turn allows us to pass a scriptblock instead of a string value as the substitution pattern.\r\n\r\nSince only wiring is required, we can accomplish this with:\r\n\r\n\r\n    if `<substitution>` argument is a ScriptBlock\r\n        convert `<substitution>` to a `MatchEvaluator` instance\r\n        pass MatchEvaluator to Regex.Replace() instead of \"`<substitution>`\"\r\n\r\n**Update:**\r\n\r\nTo support arbitrary delegates  (like existing `MatchEvaluator`s and `PSMethod`s), \r\n\r\n    if `<substitution>` argument is not a string\r\n        attempt to convert `<substitution>` to a `MatchEvaluator` instance\r\n        pass MatchEvaluator to Regex.Replace() instead of \"`<substitution>`\"\r\n"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/372659587","html_url":"https://github.com/PowerShell/PowerShell/pull/6029#issuecomment-372659587","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/6029","id":372659587,"user":{"login":"IISResetMe","id":7413755,"avatar_url":"https://avatars3.githubusercontent.com/u/7413755?v=4","gravatar_id":"","url":"https://api.github.com/users/IISResetMe","html_url":"https://github.com/IISResetMe","followers_url":"https://api.github.com/users/IISResetMe/followers","following_url":"https://api.github.com/users/IISResetMe/following{/other_user}","gists_url":"https://api.github.com/users/IISResetMe/gists{/gist_id}","starred_url":"https://api.github.com/users/IISResetMe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IISResetMe/subscriptions","organizations_url":"https://api.github.com/users/IISResetMe/orgs","repos_url":"https://api.github.com/users/IISResetMe/repos","events_url":"https://api.github.com/users/IISResetMe/events{/privacy}","received_events_url":"https://api.github.com/users/IISResetMe/received_events","type":"User","site_admin":false},"created_at":"2018-03-13T13:10:23Z","updated_at":"2018-03-13T13:10:23Z","author_association":"CONTRIBUTOR","body":"Thanks @daxian-dbw! Couldn't get `$_` to work inside the MatchEvaluator and then life got in the way :)\r\n\r\nLooks good!"}}
{"actor":{"display_login":"IISResetMe"}}