On several occasions, I have felt that built-in regex support in GNU APL would be very helpful.
Implementing it should be rather simple, but I'd like to discuss how such an API should look in order for it to be as useful as possible.
I was thinking of the following form:
regex ⎕Regex string
The way I envision this to work, is to have the function return ⍬ if there is no match, or a string containing the match, if there is one:
'f..' ⎕Regex 'xzooy'
┏⊖┓
┃0┃
┗━┛
'f..' ⎕Regex 'xfooy'
'foo'
If the regex has subexpressions, those matches should be returned as individual strings:
'([0-9]+)-([0-9]+)-([0-9]+) '⎕Regex '2017-01-02'
┏→━━━━━━━━━━━━━━━┓
┃"2017" "01" "02"┃
┗∊━━━━━━━━━━━━━━━┛
What do you think? Is this a reasonable way to implement it? Any suggestions about alternative API's?
Regards,
Elias