Skip to content

Instantly share code, notes, and snippets.

@hanafivan
Created July 2, 2020 00:52
Show Gist options
  • Select an option

  • Save hanafivan/59188f97ba781a8082001a1b2ce96f0e to your computer and use it in GitHub Desktop.

Select an option

Save hanafivan/59188f97ba781a8082001a1b2ce96f0e to your computer and use it in GitHub Desktop.
snippet to
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