PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

editor.research() assigns empty string to non-participating groups (instead of the preferred None)

Open alankilborn opened this issue 1 year ago • 0 comments

Under PS 3.0.16.0 (and 2.0.0.0 as well), consider this script:

# -*- coding: utf-8 -*-
from __future__ import print_function

# see

from Npp import *

def match_found(m): print(m.groups())
matches = []
editor.research(r'test data: (\d+)\.?(\d+)?', match_found)

# test data: 24

Run the script with the script itself as the active tab in Notepad++.

Actual Output: ('24', '')

Preferred output: ('24', None)

Rationale for preferred output, see https://docs.python.org/3/library/re.html#match-objects:~:text=Match.groups(default%3DNone), duplicated here:

image

Note that PS does not support the default argument for m.groups() and I'm not requesting that here (that would be a feature/enhancement request, whereas this current issue is more of a bug/enhancement request).

alankilborn avatar Jan 24 '24 11:01 alankilborn