{"id":1005535,"date":"2023-07-14T13:07:39","date_gmt":"2023-07-14T17:07:39","guid":{"rendered":"https:\/\/dlibwwwcit.services.brown.edu\/create\/cds_dev2\/?page_id=1005535"},"modified":"2023-10-03T20:02:03","modified_gmt":"2023-10-04T00:02:03","slug":"regular-expressions-workshop","status":"publish","type":"page","link":"https:\/\/library.brown.edu\/create\/cds\/workshops\/regular-expressions-workshop\/","title":{"rendered":"Regular Expressions Workshop"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Regular Expressions Workshop<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">This page is at&nbsp;http:\/\/brown.edu\/go\/regex&nbsp;|&nbsp;<a rel=\"noreferrer noopener\" href=\"http:\/\/web.mit.edu\/hackl\/www\/lab\/turkshop\/slides\/regex-cheatsheet.pdf\" target=\"_blank\">PDF of handout<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Challenges are in increasing difficuty \u2014 try them in order. See how far you get in the alotted time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 0: Introduction (5 minutes)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>What are regular expressions?<\/li>\n\n\n\n<li>Examples of use:\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/regex101.com\/r\/sS3vM6\/2\" target=\"_blank\" rel=\"noreferrer noopener\">text mining<\/a><br><em>Find me all the names of characters in P&amp;P mentioned by other characters<\/em><br>&#8220;[^&#8221;]*M(s|rs?)\\.(\\s+[A-Z]\\w+)+[^&#8221;]*&#8221;<\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"http:\/\/regex101.com\/r\/nN4fE3\/2\" target=\"_blank\">data structure<\/a><br><em>Find the mistake in my data structure<\/em><br>(&#8220;type&#8221;)[^{}]+&#8221;type&#8221;<br>(not a good regex, but good enough)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Part 1: Literals, symbols, and flags (10 minutes)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"http:\/\/regex101.com\/r\/iI9dA0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Match all \u201ccolor&#8221; and correct them to the Canadian spelling<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/iI9dA0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Put a double carriage return between paragraphs<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/pR6xE0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Find all Rhode Island telephone numbers<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/pR6xE0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Remove all 2015 entries<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/pR6xE0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Remove the second column of this spreadsheet<\/a><br><em>(note that the slash&nbsp;\/&nbsp;must be escaped in your regex, i.e.&nbsp;\\\/)<\/em><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Part 2: Character classes, boundaries, and disjunction (10 minutes)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"http:\/\/regex101.com\/r\/iI9dA0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Match all 4-letter words beginning with&nbsp;<em>f<\/em>&nbsp;(any case). Don&#8217;t use the&nbsp;<strong>i<\/strong>&nbsp;flag<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/iI9dA0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Match all 5-letter words beginning with a capital letter<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/pR6xE0\/2\" target=\"_blank\" rel=\"noreferrer noopener\">Remove all entries from Rhode Island or area code 497 in any other year than 2014<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Part 3: Quantifiers (10 minutes)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"http:\/\/regex101.com\/r\/sS3vM6\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Match all capitalized words<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/sS3vM6\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Get a list of names that start with &#8220;Mr.&#8221; or &#8220;Mrs.&#8221;<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/sS3vM6\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Match all quotations<\/a>&nbsp;\u2014 e.g.&nbsp;<em>I said:&nbsp;&#8220;Hello&#8221;<\/em><\/li>\n\n\n\n<li><a href=\"http:\/\/regex101.com\/r\/sS3vM6\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Match all quotations that mention Mr. Bingley<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Part 4: Backreferences (10 minutes)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" href=\"http:\/\/regex101.com\/r\/gH2jE1\/1\" target=\"_blank\">Find all URLs and make them into HTML links<\/a><br>An example:\u00a0http:\/\/google.com\u00a0becomes\u00a0<a href=\"http:\/\/google.com\">google.com<\/a><br>Hints:\n<ul class=\"wp-block-list\">\n<li>For the purpose of this exercise, URLs are of the form:&nbsp;http:\/\/aaa\/bbb\/ccc.ddd<\/li>\n\n\n\n<li>An HTML link is of the form:\u00a0&lt;a href=&#8221;[URL]&#8221;&gt;[text]&lt;\/a&gt;<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Regex crossword! (sort of) &#8211;&nbsp;<a href=\"http:\/\/regexcrossword.com\/howtoplay\" target=\"_blank\" rel=\"noreferrer noopener\">how to play<\/a><br><a href=\"http:\/\/regexcrossword.com\/challenges\/beginner\/puzzles\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Beatles (easy)<\/a>&nbsp;|&nbsp;<a href=\"http:\/\/regexcrossword.com\/challenges\/intermediate\/puzzles\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Always remember (intermediate, includes quantifiers)<\/a>&nbsp;|&nbsp;<a href=\"http:\/\/regexcrossword.com\/challenges\/hamlet\/puzzles\/1\" target=\"_blank\" rel=\"noreferrer noopener\">Yikes!<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Regular Expressions Workshop This page is at&nbsp;http:\/\/brown.edu\/go\/regex&nbsp;|&nbsp;PDF of handout Challenges are in increasing difficuty \u2014 try them in order. See how far you get in the alotted time. Part 0: Introduction (5 minutes) Part 1: Literals, symbols, and flags (10 minutes) Part 2: Character classes, boundaries, and disjunction (10 minutes) Part 3: Quantifiers (10 minutes) <a href=\"https:\/\/library.brown.edu\/create\/cds\/workshops\/regular-expressions-workshop\/\" class=\"more-link\">&#8230;<span class=\"screen-reader-text\">  Regular Expressions Workshop<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":3926,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template-full-width-no-menu.php","meta":{"footnotes":""},"class_list":["post-1005535","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/pages\/1005535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/comments?post=1005535"}],"version-history":[{"count":4,"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/pages\/1005535\/revisions"}],"predecessor-version":[{"id":1006011,"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/pages\/1005535\/revisions\/1006011"}],"up":[{"embeddable":true,"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/pages\/3926"}],"wp:attachment":[{"href":"https:\/\/library.brown.edu\/create\/cds\/wp-json\/wp\/v2\/media?parent=1005535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}