My Coding >
Programming language >
Python >
Python FAQ >
Python: How to do Case insensitive string replacement
Python: How to do Case insensitive string replacementQuestion: How to do Case insensitive string replacement in PythonStandard tools for string replacement in Python do not offer the case insensitive option for replacement. To perform case insensitive replacement it is necessary to use other tools, available in python. Using pure regular expression for substitutionThis is not very good way of doing this task, because you will need to write pattern for every search pattern, but working very good in simple cases. Therefore I will show you this way only as an example of simple quick code, but do advise you to use next option with pre-compiled regular expression
It is possible to use long flags=re.IGNORECASE and short flags=re.I form of flag. Using pre-compiled regular expression with re.IGNORECASE optionTo do this operation you need to use module re. Also, we will pre-compile search patter into regular expression for future use with ignoring case
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |