Created
July 2, 2020 00:52
-
-
Save hanafivan/59188f97ba781a8082001a1b2ce96f0e to your computer and use it in GitHub Desktop.
snippet to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| JavaScript: string.replace(/\([^()]*\)/g, '') | |
| PHP: preg_replace('~\([^()]*\)~', '', $string) | |
| Perl: $s =~ s/\([^()]*\)//g | |
| Python: re.sub(r'\([^()]*\)', '', s) | |
| C#: Regex.Replace(str, @"\([^()]*\)", string.Empty) | |
| VB.NET: Regex.Replace(str, "\([^()]*\)", "") | |
| Java: s.replaceAll("\\([^()]*\\)", "") | |
| Ruby: s.gsub(/\([^()]*\)/, '') | |
| R: gsub("\\([^()]*\\)", "", x) | |
| Lua: string.gsub(s, "%([^()]*%)", "") | |
| Bash/sed: sed 's/([^()]*)//g' | |
| Tcl: regsub -all {\([^()]*\)} $s "" result | |
| C++ std::regex: std::regex_replace(s, std::regex(R"(\([^()]*\))"), "") | |
| Objective-C: | |
| NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\([^()]*\\)" options:NSRegularExpressionCaseInsensitive error:&error]; | |
| NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@""]; | |
| Swift: s.replacingOccurrences(of: "\\([^()]*\\)", with: "", options: [.regularExpression] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment