<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: repetition code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 03:23:29 GMT</pubDate>
    <description>DZone Snippets: repetition code</description>
    <item>
      <title>Repetition in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5089</link>
      <description>This irb session example helps demonstrate repetition in regular expressions using * ? + {}&lt;br /&gt;&lt;br /&gt;Definitions:&lt;br /&gt;&lt;br /&gt;? - the preceding token is optional&lt;br /&gt;+ - find the token 1 or more times&lt;br /&gt;* - find the token 0 or more times&lt;br /&gt;{n} - repeat the token n no of times&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):058:0&gt; "this song is my favourite"[/favou?rite/]&lt;br /&gt;=&gt; "favourite"&lt;br /&gt;irb(main):059:0&gt; "this song is my favorite"[/favou?rite/]&lt;br /&gt;=&gt; "favorite"&lt;br /&gt;&lt;br /&gt;irb(main):100:0&gt; "this is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this is"&lt;br /&gt;irb(main):101:0&gt; "this song is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this song is"&lt;br /&gt;irb(main):102:0&gt; "this flower is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):103:0&gt; "this video is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this video is"&lt;br /&gt;&lt;br /&gt;irb(main):105:0&gt; "anything you say"[/.*/]&lt;br /&gt;=&gt; "anything you say"&lt;br /&gt;irb(main):119:0&gt; "will be repeated"[/.*/]&lt;br /&gt;=&gt; "will be repeated"&lt;br /&gt;irb(main):116:0&gt; "good times&lt;/p&gt;"[/.*[^&lt;\/p&gt;]/]&lt;br /&gt;=&gt; "good times"&lt;br /&gt;&lt;br /&gt;irb(main):220:0&gt; "test 123 test 123"[/\d+/]&lt;br /&gt;=&gt; "123"&lt;br /&gt;irb(main):224:0&gt; "test 123 test 123"[/\d{2}/]&lt;br /&gt;=&gt; "12"&lt;br /&gt;irb(main):226:0&gt; "test 123 test 123"[/\w+/]&lt;br /&gt;=&gt; "test"&lt;br /&gt;&lt;br /&gt;irb(main):008:0&gt; "try this test that"[/try.\b\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):009:0&gt; "try this test that"[/test.\b\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):233:0&gt; "test 123 test 123"[/\w+\s\d+/]&lt;br /&gt;=&gt; "test 123"&lt;br /&gt;irb(main):248:0&gt; "test 123 test 123"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; "test 123 test 123"&lt;br /&gt;irb(main):249:0&gt; "test this test 123"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; "test 123"&lt;br /&gt;irb(main):250:0&gt; "test this test that"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):279:0&gt; "try this test that"[/try\s\w[^\s]+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):280:0&gt; "try this test that"[/test\s\w[^\s]+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):310:0&gt; "try this test that"[/test\s\w\B+/]&lt;br /&gt;=&gt; "test tha"&lt;br /&gt;irb(main):308:0&gt; "try this test that"[/try\s\w\B+./]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):309:0&gt; "try this test that"[/test\s\w\B+./]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):322:0&gt; "try this test that"[/try\s\w+\b/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):323:0&gt; "try this test that"[/test\s\w+\b/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):008:0&gt; "try this test that"[/try.\b\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):009:0&gt; "try this test that"[/test.\b\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):010:0&gt; "try this test that"[/test.\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;irb(main):011:0&gt; "try this test that"[/try.\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;&lt;br /&gt;irb(main):012:0&gt; "try this test that"[/try\s\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):013:0&gt; "try this test that"[/test\s\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):015:0&gt; "try this test that"[/try\s\w+\s\w+/]&lt;br /&gt;=&gt; "try this test"&lt;br /&gt;&lt;br /&gt;irb(main):041:0&gt; "try this test that"[/\w+\s\w+$/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;irb(main):043:0&gt; "try this test that"[/^\w+\s\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: Similar to CSS the more specific an expression or selector is the less ambiguous it is.</description>
      <pubDate>Sat, 02 Feb 2008 13:56:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5089</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Calendar Loops</title>
      <link>http://snippets.dzone.com/posts/show/2659</link>
      <description>this program is very usefull when you need to know the list of dates of a repetitive task in the week.&lt;br /&gt;&lt;br /&gt;I create this program to fill the records of my teaches in a school.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int meses[12]={31,28,31,30,31,30,31,31,30,31,30,31};&lt;br /&gt;int dias[365][3];&lt;br /&gt;/*&lt;br /&gt;0 Lunes&lt;br /&gt;1 Martes&lt;br /&gt;2 Miercoles&lt;br /&gt;3 Jueves&lt;br /&gt;4 Viernes&lt;br /&gt;5 Sabado&lt;br /&gt;6 Domingo&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int cursos[7][4]={{0,0,0,0},{2,2,0,0},{1,0,1,1},{0,1,0,0},{0,0,2,2},{0,0,0,0},{0,0,0,0}};&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;    int i,j,k;&lt;br /&gt;    dias[0][0]=5;&lt;br /&gt;    for (i=1;i&lt;365;i++){&lt;br /&gt;        dias[i][0]=(dias[i-1][0]+1)%7;                       &lt;br /&gt;    }    &lt;br /&gt;    k=0;&lt;br /&gt;    for (i=0;i&lt;12;i++){&lt;br /&gt;        for (j=1;j&lt;=meses[i];j++){&lt;br /&gt;            dias[k][1]=i;    &lt;br /&gt;            dias[k][2]=j;&lt;br /&gt;            k++;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    for (i=0;i&lt;365;i++){&lt;br /&gt;       // bool salto=false;&lt;br /&gt;        for (j=0;j&lt;4;j++){&lt;br /&gt;&lt;br /&gt;            for (k=0;k&lt;cursos[dias[i][0]][j];k++){&lt;br /&gt;                printf("6-%c \t %i - %i \n",'A'+j,dias[i][2]+1,dias[i][1]+1);&lt;br /&gt;//                salto=true;&lt;br /&gt;            }               &lt;br /&gt;        }    &lt;br /&gt;       // if (salto)&lt;br /&gt;       //    printf("\n");&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Sep 2006 20:13:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2659</guid>
      <author>jcongote (John Edgar Congote Calle)</author>
    </item>
  </channel>
</rss>
