Perl5Matcher.matches(input, pattern) is returning true for input containing semicolon even when semicolon is not in patternMatcher returns matches on a regex pattern, but split() fails to find a match on the same regex?Regular expression pattern with ? character and characterSequense contains unicode characterFinding whether a string meets a certain patternI need something to look at the characters in a string and accept the string if it only has the certain characters in Javareturning true with an occurance of a letter in a string?Java RegEx match string containing non-ASCII that exceeds given lengthRegular expression for a string contains characters not in a specific setFREJ Regex cannot match non alphanumeric charactersUsing regex/String Method: Print Words containing PatternMatch all the letters in string

Exact functors and derived functors

How does DC work with natural 20?

What is "industrial ethernet"?

What does it cost to buy a tavern?

Warnings using NDSolve on wave PDE. "Using maximum number of grid points" , "Warning: scaled local spatial error estimate"

Why don't we have a weaning party like Avraham did?

What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?

Designing a magic-compatible polearm

How to work with PETG? Settings, caveats, etc

Can i enter UK for 24 hours from a Schengen area holding an Indian passport?

Find the common ancestor between two nodes of a tree

Rejecting an offer after accepting it just 10 days from date of joining

Justifying Affordable Bespoke Spaceships

Prisoner on alien planet escapes by making up a story about ghost companions and wins the war

Did the CIA blow up a Siberian pipeline in 1982?

What happened to Hopper's girlfriend in season one?

Why does independence imply zero correlation?

Text alignment in tikzpicture

macOS: How to take a picture from camera after 1 minute

In the US, can a former president run again?

Encounter design and XP thresholds

Find All Possible Unique Combinations of Letters in a Word

Is "Busen" just the area between the breasts?

Explicit song lyrics checker



Perl5Matcher.matches(input, pattern) is returning true for input containing semicolon even when semicolon is not in pattern


Matcher returns matches on a regex pattern, but split() fails to find a match on the same regex?Regular expression pattern with ? character and characterSequense contains unicode characterFinding whether a string meets a certain patternI need something to look at the characters in a string and accept the string if it only has the certain characters in Javareturning true with an occurance of a letter in a string?Java RegEx match string containing non-ASCII that exceeds given lengthRegular expression for a string contains characters not in a specific setFREJ Regex cannot match non alphanumeric charactersUsing regex/String Method: Print Words containing PatternMatch all the letters in string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have a string MyString = "AP;"; or any other number of strings containing ;



When I attempt to validate that MyString matches a pattern
eg. MyPattern = "^[a-zA-Z0-9 ()+-_.]*$";



Which I believe should allow AlphaNumerics, and the characters ()+-_.]* but not ;



However the below statement is returning True!



Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_.]*$");

Perl5Matcher matcher = new Perl5Matcher();

if (matcher.matches("AP;", sepMatchPattern))
return true;
else
return false;



Can anyone explain why the semicolon keeps getting allowed through?










share|improve this question






























    1















    I have a string MyString = "AP;"; or any other number of strings containing ;



    When I attempt to validate that MyString matches a pattern
    eg. MyPattern = "^[a-zA-Z0-9 ()+-_.]*$";



    Which I believe should allow AlphaNumerics, and the characters ()+-_.]* but not ;



    However the below statement is returning True!



    Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_.]*$");

    Perl5Matcher matcher = new Perl5Matcher();

    if (matcher.matches("AP;", sepMatchPattern))
    return true;
    else
    return false;



    Can anyone explain why the semicolon keeps getting allowed through?










    share|improve this question


























      1












      1








      1








      I have a string MyString = "AP;"; or any other number of strings containing ;



      When I attempt to validate that MyString matches a pattern
      eg. MyPattern = "^[a-zA-Z0-9 ()+-_.]*$";



      Which I believe should allow AlphaNumerics, and the characters ()+-_.]* but not ;



      However the below statement is returning True!



      Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_.]*$");

      Perl5Matcher matcher = new Perl5Matcher();

      if (matcher.matches("AP;", sepMatchPattern))
      return true;
      else
      return false;



      Can anyone explain why the semicolon keeps getting allowed through?










      share|improve this question
















      I have a string MyString = "AP;"; or any other number of strings containing ;



      When I attempt to validate that MyString matches a pattern
      eg. MyPattern = "^[a-zA-Z0-9 ()+-_.]*$";



      Which I believe should allow AlphaNumerics, and the characters ()+-_.]* but not ;



      However the below statement is returning True!



      Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_.]*$");

      Perl5Matcher matcher = new Perl5Matcher();

      if (matcher.matches("AP;", sepMatchPattern))
      return true;
      else
      return false;



      Can anyone explain why the semicolon keeps getting allowed through?







      java pattern-matching






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 6:57









      Jonathan Leffler

      583k966971053




      583k966971053










      asked Feb 18 '13 at 17:51









      SolidSolid

      2016




      2016






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The problem lies in the regular expression that you have defined - ^[a-zA-Z0-9 ()+-_.]*$. Within this regular expression is a character class of alpha (upper and lower), numeric, space, parentheses, and some punctuation. One of the punctuation characters is a period. The period is not escaped, and thus it has its original meaning of any character (including a semi colon).



          This regex will match any string - it is essentially ^.*$.



          To fix this, escape the period.



          Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_\.]*$");


          Edit:



          It turns out that there is another item that I missed in there that has special meaning. The hyphen in the character class of "+-_" does not mean "plus, hyphen, or underscore". Rather, it means all the characters from 0x2B to 0x5F (inclusive). A quick test shows that ^[+-_]*$ also matches AP; because A and P are 0x41 and 0x50 and the notorious semicolon is 0x3B - all within the range of 0x2B to 0x5F.



          The correct regular expression is:



          "^[a-zA-Z0-9 ()+\-_\.]*$"






          share|improve this answer

























          • Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

            – Solid
            Feb 19 '13 at 9:26












          • @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

            – user289086
            Feb 19 '13 at 15:01











          • Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

            – Solid
            Feb 20 '13 at 9:43











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14942357%2fperl5matcher-matchesinput-pattern-is-returning-true-for-input-containing-semi%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The problem lies in the regular expression that you have defined - ^[a-zA-Z0-9 ()+-_.]*$. Within this regular expression is a character class of alpha (upper and lower), numeric, space, parentheses, and some punctuation. One of the punctuation characters is a period. The period is not escaped, and thus it has its original meaning of any character (including a semi colon).



          This regex will match any string - it is essentially ^.*$.



          To fix this, escape the period.



          Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_\.]*$");


          Edit:



          It turns out that there is another item that I missed in there that has special meaning. The hyphen in the character class of "+-_" does not mean "plus, hyphen, or underscore". Rather, it means all the characters from 0x2B to 0x5F (inclusive). A quick test shows that ^[+-_]*$ also matches AP; because A and P are 0x41 and 0x50 and the notorious semicolon is 0x3B - all within the range of 0x2B to 0x5F.



          The correct regular expression is:



          "^[a-zA-Z0-9 ()+\-_\.]*$"






          share|improve this answer

























          • Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

            – Solid
            Feb 19 '13 at 9:26












          • @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

            – user289086
            Feb 19 '13 at 15:01











          • Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

            – Solid
            Feb 20 '13 at 9:43















          1














          The problem lies in the regular expression that you have defined - ^[a-zA-Z0-9 ()+-_.]*$. Within this regular expression is a character class of alpha (upper and lower), numeric, space, parentheses, and some punctuation. One of the punctuation characters is a period. The period is not escaped, and thus it has its original meaning of any character (including a semi colon).



          This regex will match any string - it is essentially ^.*$.



          To fix this, escape the period.



          Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_\.]*$");


          Edit:



          It turns out that there is another item that I missed in there that has special meaning. The hyphen in the character class of "+-_" does not mean "plus, hyphen, or underscore". Rather, it means all the characters from 0x2B to 0x5F (inclusive). A quick test shows that ^[+-_]*$ also matches AP; because A and P are 0x41 and 0x50 and the notorious semicolon is 0x3B - all within the range of 0x2B to 0x5F.



          The correct regular expression is:



          "^[a-zA-Z0-9 ()+\-_\.]*$"






          share|improve this answer

























          • Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

            – Solid
            Feb 19 '13 at 9:26












          • @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

            – user289086
            Feb 19 '13 at 15:01











          • Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

            – Solid
            Feb 20 '13 at 9:43













          1












          1








          1







          The problem lies in the regular expression that you have defined - ^[a-zA-Z0-9 ()+-_.]*$. Within this regular expression is a character class of alpha (upper and lower), numeric, space, parentheses, and some punctuation. One of the punctuation characters is a period. The period is not escaped, and thus it has its original meaning of any character (including a semi colon).



          This regex will match any string - it is essentially ^.*$.



          To fix this, escape the period.



          Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_\.]*$");


          Edit:



          It turns out that there is another item that I missed in there that has special meaning. The hyphen in the character class of "+-_" does not mean "plus, hyphen, or underscore". Rather, it means all the characters from 0x2B to 0x5F (inclusive). A quick test shows that ^[+-_]*$ also matches AP; because A and P are 0x41 and 0x50 and the notorious semicolon is 0x3B - all within the range of 0x2B to 0x5F.



          The correct regular expression is:



          "^[a-zA-Z0-9 ()+\-_\.]*$"






          share|improve this answer















          The problem lies in the regular expression that you have defined - ^[a-zA-Z0-9 ()+-_.]*$. Within this regular expression is a character class of alpha (upper and lower), numeric, space, parentheses, and some punctuation. One of the punctuation characters is a period. The period is not escaped, and thus it has its original meaning of any character (including a semi colon).



          This regex will match any string - it is essentially ^.*$.



          To fix this, escape the period.



          Pattern sepMatchPattern = sepMatchCompiler.compile("^[a-zA-Z0-9 ()+-_\.]*$");


          Edit:



          It turns out that there is another item that I missed in there that has special meaning. The hyphen in the character class of "+-_" does not mean "plus, hyphen, or underscore". Rather, it means all the characters from 0x2B to 0x5F (inclusive). A quick test shows that ^[+-_]*$ also matches AP; because A and P are 0x41 and 0x50 and the notorious semicolon is 0x3B - all within the range of 0x2B to 0x5F.



          The correct regular expression is:



          "^[a-zA-Z0-9 ()+\-_\.]*$"







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 19 '13 at 15:08

























          answered Feb 18 '13 at 18:34







          user289086



















          • Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

            – Solid
            Feb 19 '13 at 9:26












          • @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

            – user289086
            Feb 19 '13 at 15:01











          • Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

            – Solid
            Feb 20 '13 at 9:43

















          • Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

            – Solid
            Feb 19 '13 at 9:26












          • @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

            – user289086
            Feb 19 '13 at 15:01











          • Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

            – Solid
            Feb 20 '13 at 9:43
















          Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

          – Solid
          Feb 19 '13 at 9:26






          Thanks MichaelT however I've added the escaping and ; still passes. Even without the escaping though strings with % or £ will still fail.

          – Solid
          Feb 19 '13 at 9:26














          @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

          – user289086
          Feb 19 '13 at 15:01





          @Ethan Ah ha, there's another thing that needs escaping in there that I missed. The dash.

          – user289086
          Feb 19 '13 at 15:01













          Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

          – Solid
          Feb 20 '13 at 9:43





          Thanks again Michael. I am confused as to why % was returning false before the escaping was introduced, if . was allowing any character to return true.

          – Solid
          Feb 20 '13 at 9:43



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14942357%2fperl5matcher-matchesinput-pattern-is-returning-true-for-input-containing-semi%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript