Skip to content

Fixed capturing group in lineBreak() #49

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

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/ru/lanwen/verbalregex/VerbalExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Builder somethingButNot(final String pValue) {
* @return this builder
*/
public Builder lineBreak() {
return this.add("(?:\\n|(\\r\\n))");
return this.add("(?:\\n|(?:\\r\\n))");
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/ru/lanwen/verbalregex/RealWorldUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static ru.lanwen.verbalregex.VerbalExpression.regex;
import static ru.lanwen.verbalregex.matchers.TestMatchMatcher.matchesTo;
Expand Down Expand Up @@ -118,4 +119,18 @@ public void oneOfShouldFindEpisodeTitleOfStarWarsMovies() {
assertThat(regex, matchesTo("Star Wars: The Empire Strikes Back"));
assertThat(regex, matchesTo("Star Wars: Return of the Jedi"));
}

@Test
public void captureAfterNewLineHasGroupNumberOne() throws Exception {

final String line_break = "\n";
final String some = "some";
final String text = " text";
final VerbalExpression expression = VerbalExpression.regex().
lineBreak()
.capture().find(some).endCapture().then(text)
.build();

assertEquals(some, expression.getText(line_break + some + text, 1));
}
}