reparse icon indicating copy to clipboard operation
reparse copied to clipboard

Groups matching not working as expected

Open vittot opened this issue 3 years ago • 1 comments

If I have the following regex group:

Full_Date:
    Basic Full_Date:
        Expression: ([0-3]?[0-9]) \. ([0-1]?[0-9]) \. (20[0-9][0-9])
        Matches: 01.01.2021
        Non-Matches: 01--01-2021 | 01.01.1990
        Groups:
            - Day
            - Month
            - Year

and the following function, associated to Basic Full_Date:

def full_date(Day, Month, Year):
    print('full_date', Day, Month, Year)
    if Day is None or Month is None or Year is None or Day=='' or Month=='' or Year=='' or len(Day) > 2 or len(Month) > 2:
         return None
    if len(Day) == 1:
        Day = '0' + Day
    if len(Month) == 1:
        Month = '0' + Month
    return {'day':Day, 'month':Month, 'year':Year}

how is it possible that when parsing the string 21.2.2021 the function is called with Day= 21.2.2021, MOnth=21 and year=2 ? It does not make any sense to me

vittot avatar Apr 27 '22 10:04 vittot

Well, two possibilities. One is that the system no longer works. It's been a little while since I've maintained it.

Second possibility is that you are using an expression as a pattern. The expression you have should be wrapped in a pattern first before use:

FullDatePattern: Order: 1 Pattern: | <Full_Date>

from datetime import timedef full_date(Date=None): Day, Month, Year = *Date

On Wed, Apr 27, 2022 at 3:46 AM Vittorio Torri @.***> wrote:

If I have the following regex group:

Full_Date: Basic Full_Date: Expression: ([0-3]?[0-9]) . ([0-1]?[0-9]) . (20[0-9][0-9]) Matches: 01.01.2021 Non-Matches: 01--01-2021 | 01.01.1990 Groups: - Day - Month - Year

and the following function, associated to Basic Full_Date:

def full_date(Day, Month, Year): print('FUllDAte', Day, Month, Year) if Day is None or Month is None or Year is None or Day=='' or Month=='' or Year=='' or len(Day) > 2 or len(Month) > 2: return None if len(Day) == 1: Day = '0' + Day if len(Month) == 1: Month = '0' + Month return {'day':Day, 'month':Month, 'year':Year}

how is it possible that when parsing the string 21.2.2021 the function is called with Day= 21.2.2021, MOnth=21 and year=2 ? It does not make any sense to me

— Reply to this email directly, view it on GitHub https://github.com/andychase/reparse/issues/14, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAS3CCB7T2V6UO7GLARSBM3VHELIFANCNFSM5UOWSO5Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

andychase avatar Oct 11 '22 09:10 andychase