package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?<=[:=!?&,;|{\[\(\n])[\x09\x20]*(?:\/(?![*+?])(?:(?:[^\n\[\\\/]*+(?:\\\\)*+(?:\\\[|\\\/|\\(?!\[))?(\[)?)+(?(1)([^\n\]\\]*+(\\\\)*+(\\\]|\\(?!\]))?)*((?<!\\)\])?))*[^\n]*?(?<![^\\]\/)(?<![^\\]\\)\/)[gim]{0,3}[\x09\x20]*+(?![^}\]\),;:.\n])`)
var str = `// Regular expressions
r = /([\\/])?([^\\/]*)$/;
r = /([\\/])?([^\\:/]*)$/; // коммент
/abc\[def\[^\s[\]/]ghi/g.test(s);// здеÑÑŒ одна пара квадратных Ñкобок!
r = /\//i;
r = /[/\*]/img; // коммент
r = /[a-z]{5}/;
r = /[a-z]{1,5}/;
r = /([a-z])+/;
r = /([a-z]{1,5})+/;
r = /f([a-z])/;
r = /f([a-z]+)*/;
r = /a(b)c(d)/;
r = /a(b)?c(d)+?/;
r =(t|/\*/.test(s));
r =(t|/\*/); // коммент
r =/./.test(s) && f();
r=/[a-z]/.test(s) && f();
var a = [/a\/, \/b/];
a=[/a/,/b/];
var o = { r: /./, x: 2 }; // коммент
o={r:/./,x:2};
var x = a && /b/.test(s);
x = a ? /b/ : /c/;// коммент
x=a?/b/:/c/;
x=a?/b\\/:/c\/\\/; // коммент
x=a?/b\\/:/c\/\\/; // коммент
x = !/a/.test(s);
x = f(/./i);
x=1*s.replace(/^[^\d]*(\d+).*$/,'$1')/2;
/\s\n\s+\/\/\\\\/.test(s)?f(null):f(/\\/);
/\s\n\s+\/\/\\\\/.test(s)?f(null):f(/\\fghj[\[fghj\]]kl/), /fght/;
a=s.search(/\s\n\s+\/f\//gi);
r=/>\.jjj\n<\s\</
.exec(s);
r=/ \n \s/g,
t=/'/g
;
// Not a regular expressions
var n = 1/2;// коммент
n = 1/2/3;
n = 1/2/p;
n = 1/(2/p); // коммент
n = 1/this.n/3;
n = 1/this.f(5+4)/3;
n = 1/this.f(2/3);
n = 1/2 + (function() { return 3/4; })();
n = 1/2*(this.x/3 + 2);
n = 1/2*(this.x + 2/3);
n =p/2,t=3/p;
n = f(1/2) + f(3/2);`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/