Page MenuHomePhabricator

Replace unnecessary [\s\S] patterns with DOTALL where appropriate
Open, LowPublic

Description

Several regular expressions in Pywikibot use the pattern [\s\S] to match arbitrary characters including line breaks.

Examples:

[\s\S]*?
[\S\s]*?

This construction is a workaround for matching newlines and can be replaced by the more idiomatic DOTALL mode:

.*?

with:

re.DOTALL

or, for limited scope:

(?s:...)

Using DOTALL improves readability and makes the intention of the regex clearer. The current [\s\S] patterns are harder to understand because they rely on the fact that every character is either whitespace or non-whitespace.

This task is to review existing occurrences and replace them where appropriate. Complex regexes where DOTALL would affect unrelated parts should keep a scoped inline flag or remain unchanged.

See: https://codesearch.wmcloud.org/pywikibot/?q=%5C%5B%5C%5CS%5C%5Cs%5C%5D%7C%5C%5B%5C%5Cs%5C%5CS%5C%5D&files=&excludeFiles=&repos= to find occurences.

Event Timeline

Xqt triaged this task as Low priority.Jul 23 2026, 4:02 PM

Change #1319540 had a related patch set uploaded (by Prakhar0804; author: Prakhar0804):

[pywikibot/core@master] [refactor] Replace unnecessary [\s\S] patterns with DOTALL where appropriate

https://gerrit.wikimedia.org/r/1319540

Thank you @Prakhar0804 for this patch. I'll review it soon. Please add yourself to the AUTHORS.rst file if not already done.

@Xqt Hey Buddy ! if you're free please look for the code-review.....so that if it's correct we could get it merged.