I have the following string
[custID] = 'A99999999'
I am trying the following to remove the square brackets and the single quotes
Regex.Replace(sql, "/[\[\]']+/g", " ")
but that's not working. I keep getting the same results
Note: sql is a variable holding the string above.
I want the result to be
custID = A99999999
If you want to remove the [ or the ] , use the expression: "\\[|\\]" . The two backslashes escape the square bracket and the pipe is an "or".
Just make sure ] is the first character (or in this case, first after the ^ . result2 = Regex. Replace(result2, "[^][A-Za-z0-9/.,>#:\s]", "");
The easiest way to get rid of brackets is with a regular expression search using the Python sub() function from the re module. We can easily define a regular expression which will search for bracket characters, and then using the sub() function, we will replace them with an empty string.
By placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regex. Only parentheses can be used for grouping.
\[
doesn't do what you think it does. Nor is Regex
the same as in Perl. Try this instead:
Regex.Replace(sql, @"[\[\]']+", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With