I am using a Regex to find a pattern within a string. After I find a match I would then like to remove it from the existing string.
For example:
starting string ex: "Billed Hours (.5);"
converted string: "Billed Hours"
The regex pattern I am using is @"([az.]+);$" - Not sure if this is correct, I want to check that only whole numbers or decimals are within the parentheses. If the pattern matches then remove parentheses, the value inside as well as the following semi-colon.
This is what I have so far:
string testString = "Billed Hours (.5);"
testString = Regex.Replace(testString, @"\([a-z.]+\);$", "");
This is in C#.
Any ideas?
考虑...
string testString= Regex.Replace(testString, @"\(\d*\.?\d*]*\);$", "");
Try the regex:
@"\s+\([^)]+\);$"
And replace by nothing.
The \\s+
is to avoid having to trim spaces and [^)]+
matches any character except closing paren.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.