Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created December 19, 2022 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/89df59e9a837ce48de9916139d069ad6 to your computer and use it in GitHub Desktop.
Save chuongmep/89df59e9a837ce48de9916139d069ad6 to your computer and use it in GitHub Desktop.
string pattern = @"_detached.*";
string replacement = "";
Regex rgx = new Regex(pattern);
fileName = rgx.Replace(fileName, replacement);
if (fileName.EndsWith(".rvt")) fileName = fileName.Replace(".rvt", String.Empty);
Source_File_Rvt = filename;
import re
test = ["dadaa__detached_1","dadaa__detached_3","dadaa__detached_2"]
# pattern regex to match the string with _detached and remove all _detached and all characters after it
pattern = re.compile(r'_detached.*')
# replace the string with empty string
test = [pattern.sub('', i) for i in test]
# print the list
print(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment