{"id":2498,"date":"2009-11-20T14:05:38","date_gmt":"2009-11-20T14:05:38","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/20\/regular-expressionsa-cheat-sheet\/"},"modified":"2018-01-08T15:05:05","modified_gmt":"2018-01-08T20:05:05","slug":"regular-expressionsa-cheat-sheet","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/20\/regular-expressionsa-cheat-sheet\/","title":{"rendered":"Regular Expressions&#8230;a Cheat Sheet!"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <p>In <a href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/06\/segmenting-coinsa-tutorial-on-blob-analysis\/\">my last Pick<\/a>, I singled out someone who has contributed widely to image-processing discussions on the <a>CSSM newsgroup<\/a>. Today, I want to recognize a stalwart contributor to the MATLAB community, both through CSSM and through his numerous submissions\r\n      to the MATLAB Central File Exchange. Anyone who has spent time posing or answering questions on CSSM knows of <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/4309\">us<\/a>. And though he has labeled all of his 41 submissions as \"pedestrian,\" most are anything but.\r\n   <\/p>\r\n   <p>Today's Pick comes to us from us. (Sounds circular, but power-user us apparently doesn't like capitals--or three-letter names!).\r\n      In <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/20589-rex--a-pedestrian-regular-expression-operator-synopsis-generator\">rex: a pedestrian regular expression operator synopsis generator<\/a>, us has provided a very handy cheat sheet, of sorts, for creating <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f0-42649.html\">Regular Expressions<\/a>. For those of you who haven't yet delved the mysteries of regular expressions, they are powerful devices for searching or\r\n      manipulating strings. But they can be cryptic to create or to decipher. Us's rex is a single-page reference for writing regular\r\n      expressions. The commands can be written to the Command Window, or displayed in a listbox:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/rex_potw.png\"> <\/p>\r\n   <p>Many of us's files are Pickworthy. His functions are broadly useful, and his code is powerful, concise, and well-written.\r\n      Give his files a browse--there's something there for everyone!\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2498#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_d489cf87ccca47e083161f57b2f26763() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='d489cf87ccca47e083161f57b2f26763 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' d489cf87ccca47e083161f57b2f26763';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_d489cf87ccca47e083161f57b2f26763()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.8<br><\/p>\r\n<\/div>\r\n<!--\r\nd489cf87ccca47e083161f57b2f26763 ##### SOURCE BEGIN #####\r\n%% Regular Expressions...a Cheat Sheet!\r\n%%\r\n% In\r\n% <https:\/\/blogs.mathworks.com\/pick\/2009\/11\/06\/segmenting-coinsa-tutorial-on-blob-analysis\/ my last Pick>, I singled out someone who has contributed\r\n% widely to image-processing discussions on the <http:\/\/ CSSM newsgroup>. Today, I\r\n% want to recognize a stalwart contributor to the MATLAB\r\n% community, both through CSSM and through his numerous submissions to the\r\n% MATLAB Central File Exchange. Anyone who has spent time posing or answering\r\n% questions on CSSM knows of <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/4309 us>.\r\n% And though he has labeled all of his 41 submissions as \"pedestrian,\" most\r\n% are anything but.\r\n\r\n%%\r\n% Today's Pick comes to us from us. (Sounds circular, but power-user us\r\n% apparently doesn't like capitalsREPLACE_WITH_DASH_DASHor three-letter names!). In <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/20589-rex--a-pedestrian-regular-expression-operator-synopsis-generator rex: a pedestrian regular expression operator synopsis generator>,\r\n% us has provided a very handy cheat sheet, of sorts, for creating\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_prog\/f0-42649.html Regular Expressions>. For those of\r\n% you who haven't yet delved the mysteries of regular expressions, they are\r\n% powerful devices for searching or manipulating strings. But they can be\r\n% cryptic to create or to decipher. Us's rex is a single-page reference\r\n% for writing regular expressions. The commands can be written to the\r\n% Command Window, or displayed in a listbox:\r\n\r\n%%\r\n% \r\n% <<rex_potw.png>>\r\n% \r\n\r\n%%\r\n% Many of us's files are Pickworthy. His functions are broadly useful, and his code is powerful, concise, and\r\n% well-written. Give his files a browseREPLACE_WITH_DASH_DASHthere's something there for\r\n% everyone!\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2498#respond Comments?>\r\n##### SOURCE END ##### d489cf87ccca47e083161f57b2f26763\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   In my last Pick, I singled out someone who has contributed widely to image-processing discussions on the CSSM newsgroup. Today, I want to recognize a stalwart contributor to the MATLAB... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/20\/regular-expressionsa-cheat-sheet\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2498"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2498"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2498\/revisions"}],"predecessor-version":[{"id":9296,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2498\/revisions\/9296"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}