Skip to content
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

RegexBuilder should document that it does not incorporate flags into string-representation #246

Closed
lukaslueg opened this issue Jun 9, 2016 · 4 comments
Labels

Comments

@lukaslueg
Copy link
Contributor

AFAICS regex::RegexBuilder does not incorporate flags into the string representation of the final regex.

let re = regex::RegexBuilder::new("foo").case_insensitive(true).compile().unwrap();
assert_eq!(re.as_str(), "(?i)foo");

panics because "foo" != "(?i)foo".

Am I confused about something here? Otherwise this should at least be documented :-)

@BurntSushi
Copy link
Member

The string representation is the exact pattern given. The docs on the Display impl and as_str method say:

Shows the original regular expression.

How can the documentation be improved?

@lukaslueg
Copy link
Contributor Author

I was under the impression that the string representation would by equivalent to the pattern and the flags set on RegexBuilder. That is, given ::new('foo') and .case_insensitive(true), the string representation is (?i)foo.

@BurntSushi
Copy link
Member

Right, but it's not. I'm asking: how might the docs be improved so that you don't get that impression?

@lukaslueg
Copy link
Contributor Author

Maybe a note in RegexBuilder::compile():

Consume the builder and compile the regular expression.
Note that the resulting `Regex::as_str()` returns the verbatim pattern given to `RegexBuilder::new()` without incorporating the flags set thereafter.

@BurntSushi BurntSushi added the bug label Jul 10, 2016
@BurntSushi BurntSushi changed the title RegexBuilder does not incorporate flags into string-representation RegexBuilder should document that it does not incorporate flags into string-representation Jul 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants