Regex Match Problem

David MacQuigg dmq at gain.com
Wed Mar 10 18:04:00 CET 2004


On 10 Mar 2004 07:17:12 -0800, bradwiseathome at hotmail.com (bdwise)
wrote:

>I have this in my body tag:
>
>something();something();
>document.thisForm.textBox1.focus();something();
>
>And I want to find a part between the semicolons that ends in focus()
>and remove the entire value between the semicolons.
>
>My Regular Expression looks like this but it is not matching, can
>anyone help?
>
>";([^.]*).focus()"

You need to escape the metacharacters.  Try
r";.*\.focus\(\).*;"
Also, use a raw quote, so you don't have to escape the escapes.

Don't forget to set re.DOTALL if you want the '.*' to capture newlines
also.

There is a nice interactive tool for testing these expressions at
../Pyton23/Tools/Scripts/redemo.py

There is a good intro to regular expressions at
http://www.amk.ca/python/howto/regex/

-- Dave




More information about the Python-list mailing list