isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

Regex matches #154

Closed curiousdannii closed 8 years ago

curiousdannii commented 8 years ago

It would be nice if it was possible to match regexs and extract groups from them.

As a syntax suggestion, what if :<str><str><falsey> was regex testing as it is now, and :<str><str><truthy> was matching.


From PPCG chat:

A list of matches would be helpful I'm sure, but it would get confusing if there was also groups within the pattern... Maybe the third operator could specify what format the results should be in 0: count of matches 1: text of first match 2: list of [matchedText,subgroups...] 3: list of texts of matches 4: list of [[matchedText,subgroups...],[],[]] it would probably also help to get the index of the match too, maybe it could be a dict rather than a list

isaacg1 commented 8 years ago

Implemented. https://github.com/isaacg1/pyth/commit/3573e7b9d0b7122726e01d36ffd1f5546108bb5f

Leaving this thread open for more ideas for further operations.