-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support for named groups into a single value? #13
Comments
There's not a way to do that currently. Today, RegExtract only binds named capture groups to named properties, and non-named groups to positional arguments. I understand your scenario—I'll put some thought into it. Possible approaches that come to mind:
|
Ah thanks, I guess for now I can just do something like this: const string expression = @"C:/SomePath/(?<ParentDir>.*)/(?<FileName>.*)\.txt";
var (_, fileName) = line.Extract<(string ParentDir, string FileName)>(expression); This also kind of makes it apparent I'm not using the first group. const string expression = @"C:/SomePath/.*/(?<FileName>.*)\.txt";
var fileName = line.Extract<string>(expression); |
So I tried something similar to this: var expression = new Regex("\\.\\/(?<filePath>(?!https?\\\\:).*?)[\\)\\\"]", RegexOptions.ECMAScript);
var fipePaths = line.Extract<IEnumerable<string>>(expression); And I get an error it can't find the named expression. I also tried this just for completions sake: var expression = new Regex("\\.\\/(?<filePath>(?!https?\\\\:).*?)[\\)\\\"]", RegexOptions.ECMAScript);
var fipePaths = line.Extract<(IEnumerable<string> filePath, object _)>(expression); But I still get an exception telling me it can't find a named binding for "filePath". I hope this helps, and I'd understand if it's out of scope for this library. |
Created Issue #14 to give you a flag that should support most of the examples above. I totally understand your point about wanting to use Named Capture Groups just for readability, not for binding. I did think of a possible workaround. If you don't use the capture group names somewhere else, you can still document your captures using regex comments ( |
Ah thanks, that's a viable workaround. |
Hi, I see you have an option for mapping named groups to properties but it's not clear to me if I can do something like this:
This is probably a bad example but, I find myself mostly using regex to match a single group and I like having them named for readability.
By the tuple example, it appears your library may support this but I'm not sure.
Thanks!
The text was updated successfully, but these errors were encountered: