{"id":462,"date":"2010-12-21T21:15:29","date_gmt":"2010-12-21T21:15:29","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=462"},"modified":"2026-06-17T09:25:28","modified_gmt":"2026-06-17T08:25:28","slug":"regex-ismatch","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/regex-ismatch\/regex-ismatch","title":{"rendered":"Regex IsMatch"},"content":{"rendered":"<h4>Notes about Regex::IsMatch<\/h4>\n<pre><code>\r\nif (!System::Text::RegularExpressions::Regex::IsMatch (this-&gt;MyString-&gt;Text, \"[0-9a-fA-f]{1,3}\" ))\r\n   MessageBox::Show ( \"Invalid value\" );\r\n<\/code><\/pre>\n<p>The problem with the above expression is that it doesn&#8217;t match what it should. There are 2 special characters, ^ and $ which specify the beginning and the end of the string to match. The way you used it, it matches any of the characters in the string. If you have a valid character, it will ignore the rest. Now, if you add an ending $, the expression will not accept a string that doesn&#8217;t end in a valid (or its understanding of &#8220;valid&#8221;) character. If you will add the ^ in front, only 3 character hexadecimal strings will pass the filter. BTW, I believe you meant to use &#8220;[0-9a-fA-F]{1,3}&#8221;, not f. This way, even W will match, because it is between A and f.<br \/>\nTry the following and observe the differences:<\/p>\n<pre><code>\r\nif (!System::Text::RegularExpressions::Regex::IsMatch\r\n\t\/\/(this-&gt;myTextBox-&gt;Text, \"[0-9a-fA-F]{1,3}\" ))\r\n\t\/\/(this-&gt;myTextBox-&gt;Text, \"^[0-9a-fA-F]{1,3}\" ))\r\n\t\/\/(this-&gt;myTextBox-&gt;Text, \"[0-9a-fA-F]{1,3}$\" ))\r\n\t(this-&gt;myTextBox-&gt;Text, \"^[0-9a-fA-F]{1,3}$\" ))\r\n{\r\n\tMessageBox::Show (\"Address 2: Invalid value\");\r\n<\/code><\/pre>\n<p>The use of enclosing ^ and $ tokens to indicate that the entire string, not just a substring, must match the regular expression.<\/p>\n<p>Regular expression examples can be found in help at: ms-help:\/\/MS.VSCC.v90\/MS.MSDNQTR.v90.en\/dv_fxfund\/html\/e9fd53f2-ed56-4b09-b2ea-e9bc9d65e6d6.htm<\/p>\n<p>A good resource for expressions: <a href=\"http:\/\/www.regular-expressions.info\/reference.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.regular-expressions.info\/reference.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes about Regex::IsMatch if (!System::Text::RegularExpressions::Regex::IsMatch (this-&gt;MyString-&gt;Text, &#8220;[0-9a-fA-f]{1,3}&#8221; )) MessageBox::Show ( &#8220;Invalid value&#8221; ); The problem with the above expression is that it doesn&#8217;t match what it should. There are 2 special characters, ^ and $ which specify the beginning and the end of the string to match. The way you used it, it matches any [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-regex-ismatch"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":1625,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/462\/revisions\/1625"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}