Próbuję parsować niektóre docstrings.regex: string z opcjonalnymi częściami
przykładem docstrings jest:
Test if a column field is larger than a given value
This function can also be called as an operator using the '>' syntax
Arguments:
- DbColumn self
- string or float value: the value to compare to
in case of string: lexicographic comparison
in case of float: numeric comparison
Returns:
DbWhere object
Zarówno Arguments
i Returns
części są opcjonalne. Chcę, aby moje wyrażenie regularne zwracało jako grupy opis (pierwsze wiersze), część Arguments
(jeśli jest obecna) i część Returns
(jeśli jest obecna).
regex mam teraz jest:
m = re.search('(.*)(Arguments:.*)(Returns:.*)', s, re.DOTALL)
i pracuje w przypadku wszystkie trzy części są obecne, ale nie tak szybko, jak Arguments
lub części Returns
nie są dostępne. Próbowałem kilku wariacji z nie wymagającymi chciwości modyfikatorami, takimi jak ??
, ale bezskutecznie.
Edit: Kiedy Arguments
i Returns
części są obecne, tak naprawdę chciałby tylko, aby dopasować tekst po Arguments:
i Returns:
odpowiednio.
Dzięki!
Czy zamówienie jest zawsze stałe? I. e., Jest "Arguments" zawsze po standardowym tekście i przed 'Returns'? –
Tak, zamówienie jest zawsze stałe. – BioGeek