I made a tiny database with books and trying to get titles, authors and year of book with regex in c# but error occured.
Database looks like this:
Eragon // Christopher Paolini // 2005
The Fellowship of the Ring // J. R. R. Tolkien // 1954
And code:
Regex r = new Regex(@"(?<title>(.*)//" +
                    @"(?<author>(.*)//" +
                    @"(?<year>(.*)$");
Error:
parsing "(?<tytul>(.*)//(?<autor>(.*)//(?<rok>(.*)$" - Not enough )'s.
                You forget to close all the named capturing groups.
@"(?<tytul>(.*))//(?<autor>(.*))//(?<rok>(.*))$"
               ^               ^             ^
DEMO
By turning the greedy quantifiers .* at the first to non-greedy .*? would avoid backtracking.
@"^(?<tytul>(.*?))//(?<autor>(.*?))//(?<rok>(.*))$"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With