diff --git a/lib/regin/character.rb b/lib/regin/character.rb index b71f860..12a9199 100644 --- a/lib/regin/character.rb +++ b/lib/regin/character.rb @@ -26,14 +26,14 @@ def to_s(parent = false) end end - def to_regexp(anchored = true) + def to_regexp(anchored = false) re = to_s(true) re = "\\A#{re}\\Z" if anchored Regexp.compile(re, ignorecase) end def match(char) - to_regexp.match(char) + to_regexp(true).match(char) end def include?(char) diff --git a/lib/regin/collection.rb b/lib/regin/collection.rb index 2a58dd2..f1f7032 100644 --- a/lib/regin/collection.rb +++ b/lib/regin/collection.rb @@ -32,7 +32,7 @@ def +(other) self.class.new(@array + ary) end - def to_regexp(anchored = true) + def to_regexp(anchored = false) re = to_s(true) re = "\\A#{re}\\Z" if anchored Regexp.compile(re, flags) diff --git a/lib/regin/group.rb b/lib/regin/group.rb index 6f2d1c7..d682148 100644 --- a/lib/regin/group.rb +++ b/lib/regin/group.rb @@ -34,7 +34,7 @@ def to_s(parent = false) end end - def to_regexp(anchored = true) + def to_regexp(anchored = false) re = to_s re = "\\A#{re}\\Z" if anchored Regexp.compile(re) diff --git a/spec/alternation_spec.rb b/spec/alternation_spec.rb index 75313a3..abdb745 100644 --- a/spec/alternation_spec.rb +++ b/spec/alternation_spec.rb @@ -19,7 +19,7 @@ end it "should return a regexp of itself" do - @alternation.to_regexp.should == /\Aa|b|c\Z/ + @alternation.to_regexp.should == /a|b|c/ end it "should match 'a'" do @@ -97,7 +97,7 @@ end it "should return a regexp of itself" do - @alternation.to_regexp.should == /\Aa|b|c\Z/ + @alternation.to_regexp.should == /a|b|c/ end it "should apply ignorecase to child expression" do diff --git a/spec/character_range_spec.rb b/spec/character_range_spec.rb index 1a1aec3..c75221e 100644 --- a/spec/character_range_spec.rb +++ b/spec/character_range_spec.rb @@ -26,7 +26,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A[a-z]\Z/ + @range.to_regexp.should == /[a-z]/ end it "should be inspectable" do @@ -92,7 +92,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A.\Z/ + @range.to_regexp.should == /./ end it "should be inspectable" do @@ -137,7 +137,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A[a-z]{2,3}\Z/ + @range.to_regexp.should == /[a-z]{2,3}/ end it "should be inspectable" do @@ -167,7 +167,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A[^a-z]\Z/ + @range.to_regexp.should == /[^a-z]/ end it "should be inspectable" do @@ -209,7 +209,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A[a-z]\Z/i + @range.to_regexp.should == /[a-z]/i end it "should be inspectable" do @@ -246,7 +246,7 @@ end it "should return a regexp of itself" do - @range.to_regexp.should == /\A.\Z/i + @range.to_regexp.should == /./i end it "should be inspectable" do diff --git a/spec/character_spec.rb b/spec/character_spec.rb index 7d9e32c..09b408d 100644 --- a/spec/character_spec.rb +++ b/spec/character_spec.rb @@ -17,7 +17,7 @@ end it "should return a regexp of itself" do - @character.to_regexp.should == /\Aa\Z/ + @character.to_regexp.should == /a/ end it "should be inspectable" do @@ -80,7 +80,7 @@ end it "should return a regexp of itself" do - @character.to_regexp.should == /\Aa?\Z/ + @character.to_regexp.should == /a?/ end it "should be inspectable" do @@ -124,7 +124,7 @@ end it "should return a regexp of itself" do - @character.to_regexp.should == /\Aa{2,3}\Z/ + @character.to_regexp.should == /a{2,3}/ end it "should be inspectable" do @@ -157,7 +157,7 @@ end it "should return a regexp of itself" do - @character.to_regexp.should == /\Aa\Z/i + @character.to_regexp.should == /a/i end it "should be inspectable" do diff --git a/spec/expression_spec.rb b/spec/expression_spec.rb index 2dd8bf9..a80e8a0 100644 --- a/spec/expression_spec.rb +++ b/spec/expression_spec.rb @@ -18,7 +18,7 @@ end it "should return a regexp of itself" do - @expression.to_regexp.should == /\Afoo\Z/ + @expression.to_regexp.should == /foo/ end it "should have no flags" do @@ -120,7 +120,7 @@ end it "should return a regexp of itself" do - @expression.to_regexp.should == /\Afoo\Z/i + @expression.to_regexp.should == /foo/i end it "should have ignorecase flag" do @@ -177,7 +177,7 @@ end it "should return a regexp of itself" do - @expression.to_regexp.should == /\Afoo\Z/ + @expression.to_regexp.should == /foo/ end it "should have ignorecase flag" do diff --git a/spec/group_spec.rb b/spec/group_spec.rb index a1f053d..a0b308e 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -31,7 +31,7 @@ end it "should return a regexp of itself" do - @group.to_regexp.should == /\A(foo)\Z/ + @group.to_regexp.should == /(foo)/ end it "should match 'foo'" do @@ -110,7 +110,7 @@ end it "should return a regexp of itself" do - @group.to_regexp.should == /\A((?i-mx:foo))\Z/ + @group.to_regexp.should == /((?i-mx:foo))/ end it "should match 'foo'" do @@ -166,7 +166,7 @@ end it "should return a regexp of itself" do - @group.to_regexp.should == /\A((?i-mx:foo))?\Z/ + @group.to_regexp.should == /((?i-mx:foo))?/ end it "should match 'foo'" do diff --git a/spec/parsable_spec.rb b/spec/parsable_spec.rb index 345ee8e..ba62d1d 100644 --- a/spec/parsable_spec.rb +++ b/spec/parsable_spec.rb @@ -4,7 +4,7 @@ match do |actual| expression = Regin.parse(actual) expression.should be_a(Regin::Expression) - expected = Regexp.compile("\\A#{actual.source}\\Z", actual.options) + expected = Regexp.compile(actual.source, actual.options) expression.to_regexp.should eql(expected) end end diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 9b364df..4a03132 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -195,21 +195,21 @@ re = Regin.parse(/abc/i) re.should be_casefold re.to_s.should eql('(?i-mx:abc)') - re.to_regexp.should eql(%r{\Aabc\Z}i) + re.to_regexp.should eql(%r{abc}i) end it "should parse explict nested ignorecase" do re = Regin.parse(%r{(?-mix:foo)}i) re.should be_casefold re.to_s.should eql('(?i-mx:(?-mix:foo))') - re.to_regexp.should eql(%r{\A(?-mix:foo)\Z}i) + re.to_regexp.should eql(%r{(?-mix:foo)}i) end it "should parse implicit nested ignorecase" do re = Regin.parse(%r{(?:foo)}i) re.should be_casefold re.to_s.should eql('(?i-mx:(?i-mx:foo))') - re.to_regexp.should eql(%r{\A(?i-mx:foo)\Z}i) + re.to_regexp.should eql(%r{(?i-mx:foo)}i) end it "should parse spaces and pound sign in normal expression" do