Connected to SonarCloud or SonarQube (and which version):
And a thorough description of the problem / question:
The subject rule, str.replace should be preferred to re.sub, being triggered says re.sub can be replaced with str.replace because the pattern string has no regular expression features. While it is true that the pattern string in my instance has no regular expression features, the re.sub call is using re functionality, namely flags is set to re.IGNORECASE. I cannot obtain this with with str.replace. I do not want to call .lower on my source string before substitution because I need to preserve case in the original text (other than the bit I am replacing). Any advice?
I’ve moved your post to the category for reporting false-positives. Please see this thread and update your topic with the relevant information including a code sample.
Here is a simple example:
re.sub(“something”, “some other thing”, string, flags=re.IGNORECASE)
I can’t use string.replace() because I want to replace regardless of the case of “something”.
I can’t use string.lower().replace() because I don’t want to change the case of string.