regex - Escaping [ in Python Regular Expressions -


This reg exp searches properly to see if a string contains Harry text:

  re.search (r '\ bharry \ b', '[harry] blah', re.IGNORECASE)  

However, I must ensure that The string contains [Harry] I have tried to avoid with different numbers:

  re.search (r '\ b \ [Harry \] \ B ',' [Harry] blah ', re-introxes) Re.search (r' \ b \\ [Harry \\] \ B ',' [Harry] Blah ', re-NINICACA) Re-search (R' \ 'B \\\ [ Arry \\\] \ B ',' [Harry] Blah ', again. Introresej)  

it does not work to find a work of these solutions. What do I need to do?

Thank you!

The first one is correct:

  r '\ b \ [ Harry \] \ b ' 

but it will not match [Harry] blah as [ is not a word character And therefore there is no word limit in [ foobar [harry] blah


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -