-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement replace
and extract
#43
Comments
Yes, this would be useful, though not in pattern matching (in case that's what you were suggesting with the For example, text.search(r"f..b..") which would return a I think there would need to be an option to allow overlapping matches. For example if |
Note that it might be more appropriate to implement this in Gossamer. |
I've implemented two methods, The Gossamer implementations map these to the substring that matches, which is probably what you want. This has the added advantage that it also works with other |
what I want is this: string.withGlobalFlag {
case r"url\($url(.*?)\)" => ??? // where url is Array[String]
} and the input string might be a huge minified css file for example, so I want to extract all of those urls, but I also want to have groups |
That makes a lot of sense, and it would be useful. I think we could be more direct about the name, and call it But it's all possible, and worthwhile. Incidentally, my idea for implementing it would naturally allow multiple patterns to be defined in the partial function, but the behavior would be to only try the second (or third) patterns in the cases where the first is not found in the remainder of the string. For example, t"foobarfoobar".replace:
case r"foo" => t"baz"
case r"bar" => t"quux" would result in |
if you can do replace by groups, that would be even crazier, r"$capture(pattern)$capture2(pattern2)".findAll { result: Seq((String, String))
??? // process the result
} it kinda resembles the standard library |
I think I probably didn't give an interesting enough example in my last message. The intention is to be able to write: t"foobarfuebar".replace:
case r"f$vowels(..)" => t"g$vowels" and get Does that do what you need? |
@propensive this would be cool for other use cases, but not really. In this issue I just want to find all matches and extract capture groups |
Ah, I see. So So I think you want something closer to an optimised |
Great. Now I understand it. I think we can call it |
We have a basic implementation of I believe the best solution will be to break the partial function down into separate cases, and to pattern match on each one in turn, choosing which one to return based on which of them has the earliest result. |
Would be nice to be able to match and extract all of the occurences of regexp within string
The text was updated successfully, but these errors were encountered: