{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/12262","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/12262/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/12262/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/12262/events","html_url":"https://github.com/JuliaLang/julia/issues/12262","id":96465107,"number":12262,"title":"Regex in substrings","user":{"login":"andrewcooke","id":1429281,"avatar_url":"https://avatars.githubusercontent.com/u/1429281?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewcooke","html_url":"https://github.com/andrewcooke","followers_url":"https://api.github.com/users/andrewcooke/followers","following_url":"https://api.github.com/users/andrewcooke/following{/other_user}","gists_url":"https://api.github.com/users/andrewcooke/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewcooke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewcooke/subscriptions","organizations_url":"https://api.github.com/users/andrewcooke/orgs","repos_url":"https://api.github.com/users/andrewcooke/repos","events_url":"https://api.github.com/users/andrewcooke/events{/privacy}","received_events_url":"https://api.github.com/users/andrewcooke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":36,"created_at":"2015-07-22T03:12:00Z","updated_at":"2015-07-26T21:11:21Z","closed_at":null,"body":"This is an attempt to summarize the issues in the messy thread [here](https://groups.google.com/forum/#!topic/julia-users/GK9hMQ8ymY4).  It's quite possible I've misunderstood something (the whole thread is full of \"learning moments\") or missed part of the API, so apologies in advance.\r\n\r\nWhen parsing data it's quite common to want to match a regex from some point in a string onwards (because you've parsed up to that point and are now looking to parse the following text). Unfortunately, Julia's regex support doesn't seem to provide an efficient way of doing this.  Here are the options I see:\r\n\r\n1. Use match(regex, string, offset).  Unfortunately, the regex will match from offset *onwards* (in Python's terms, it will \"search\", not \"match\").  If you try to anchor it with `^`, the regex is anchored to the *start* of the text, not the offset.  The only way I can see to make this work is to use the \"s\" flag (single string mode), and prefix the regex with `^(?:.{offset})` (hoping i am remember the correct syntax for non-capturing group).  Which means recompiling the regex for each query and forcing the \"s\" flag.\r\n\r\n2. Use match(regex, string[offset:end]).  This makes a copy of the string, explicitly, and passes it to match.  Which is expensive for large strings.  Furthermore, any returned match is a `SubString()` based on the copy.  So if the matched data is used by the caller (eg a parser) then the (large) backing copy is not garbage collected.  This can result in huge memory leaks for unsuspecting users (like me).  The work-around is to make an explicit copy of the returned match with `utf8()` or `string(bytestring(...))` (but this still does not avoid the cost of the initial copy).\r\n\r\n3. Use match(regex, SubString(string, offset)).  Currently the match() implementation makes a copy and so this suffers from the same issues as (2).  However, I suspect that with some care, you could check whether the substring continues to the end of the backing string and, if so, avoid the copy (taking the C string from a pointer at the given offset into the backing string).  This would be as efficient as (1), but bind `^` to the current offset, which would be ideal for the parser use case.\r\n\r\nSo, if I have understood, then (3) seems like a useful enhancement.  Thanks."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/125040683","html_url":"https://github.com/JuliaLang/julia/issues/12262#issuecomment-125040683","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/12262","id":125040683,"user":{"login":"andrewcooke","id":1429281,"avatar_url":"https://avatars.githubusercontent.com/u/1429281?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewcooke","html_url":"https://github.com/andrewcooke","followers_url":"https://api.github.com/users/andrewcooke/followers","following_url":"https://api.github.com/users/andrewcooke/following{/other_user}","gists_url":"https://api.github.com/users/andrewcooke/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewcooke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewcooke/subscriptions","organizations_url":"https://api.github.com/users/andrewcooke/orgs","repos_url":"https://api.github.com/users/andrewcooke/repos","events_url":"https://api.github.com/users/andrewcooke/events{/privacy}","received_events_url":"https://api.github.com/users/andrewcooke/received_events","type":"User","site_admin":false},"created_at":"2015-07-26T21:11:21Z","updated_at":"2015-07-26T21:11:21Z","body":"That might help too, but for me the priority would be getting this into trunk.  It's working perfectly for me.  Is there anything else I can do to encourage it's adoption?"}}