{"action":"created","issue":{"url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/531","labels_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/531/labels{/name}","comments_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/531/comments","events_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/531/events","html_url":"https://github.com/BrowserSync/browser-sync/issues/531","id":63987654,"number":531,"title":"rewriteRules don't get submatches","user":{"login":"fvsch","id":243601,"avatar_url":"https://avatars.githubusercontent.com/u/243601?v=3","gravatar_id":"","url":"https://api.github.com/users/fvsch","html_url":"https://github.com/fvsch","followers_url":"https://api.github.com/users/fvsch/followers","following_url":"https://api.github.com/users/fvsch/following{/other_user}","gists_url":"https://api.github.com/users/fvsch/gists{/gist_id}","starred_url":"https://api.github.com/users/fvsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fvsch/subscriptions","organizations_url":"https://api.github.com/users/fvsch/orgs","repos_url":"https://api.github.com/users/fvsch/repos","events_url":"https://api.github.com/users/fvsch/events{/privacy}","received_events_url":"https://api.github.com/users/fvsch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-24T12:49:00Z","updated_at":"2015-03-24T13:07:20Z","closed_at":null,"body":"Hi, and thanks for a very cool tool. :+1:\r\n\r\nIn my tests with 2.4.0 the fn method for a rewriteRule wouldn't get submatches.\r\n\r\n```js\r\n{\r\n    rewriteRules: [\r\n        {\r\n            match: /\\/(test1)\\/(test2)\\//,\r\n            fn: function(found) {\r\n                console.log(arguments)\r\n                console.log(found.match(this.match))\r\n            }\r\n        }\r\n    ],\r\n}\r\n```\r\nWould it be possible to have the submatches directly as arguments (like when using a function in `str.replace(regexp, function(match, p1, p2){…})`)?\r\n\r\nAlso, it's obviously a bit late for that, but `match` is not a great name, since “a match” in English means what was actually found, not what we're looking for. So ideally we'd have something like:\r\n\r\n```js\r\n{\r\n    rewriteRules: [\r\n        {\r\n            find: /regexp with submatches/,\r\n            replaceWith: function(match, p1, p2) {…}\r\n        }\r\n    ],\r\n}\r\n```\r\nBut I digress. :)"},"comment":{"url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/comments/85486898","html_url":"https://github.com/BrowserSync/browser-sync/issues/531#issuecomment-85486898","issue_url":"https://api.github.com/repos/BrowserSync/browser-sync/issues/531","id":85486898,"user":{"login":"shakyShane","id":1643522,"avatar_url":"https://avatars.githubusercontent.com/u/1643522?v=3","gravatar_id":"","url":"https://api.github.com/users/shakyShane","html_url":"https://github.com/shakyShane","followers_url":"https://api.github.com/users/shakyShane/followers","following_url":"https://api.github.com/users/shakyShane/following{/other_user}","gists_url":"https://api.github.com/users/shakyShane/gists{/gist_id}","starred_url":"https://api.github.com/users/shakyShane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shakyShane/subscriptions","organizations_url":"https://api.github.com/users/shakyShane/orgs","repos_url":"https://api.github.com/users/shakyShane/repos","events_url":"https://api.github.com/users/shakyShane/events{/privacy}","received_events_url":"https://api.github.com/users/shakyShane/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T13:07:20Z","updated_at":"2015-03-24T13:07:20Z","body":"Yeah I want this feature too. \r\n\r\ntbh, [resp-modifier](https://github.com/shakyShane/resp-modifier) (which both BrowserSync & Foxy use) is due a rewrite anyway, so if you want to send a PR with exactly what you need, then we can use that as a basis for the rewrite. See https://github.com/shakyShane/resp-modifier/blob/master/index.js#L76-L88\r\n\r\nRe: the naming - it's `match:fn` to be consistent with resp-modifier which was originally a fork of [connect-livereload](https://github.com/intesso/connect-livereload), and although I totally agree with you, I'm more interested in consistency that of perfect naming :)"}}