<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/more-string-hacking-with-regex-and-rebus/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/08/11/more-string-hacking-with-regex-and-rebus/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/string.png" target="_blank"><img alt="" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/string.png?resize=300%2C168" class="wp-image-3037" data-recalc-dims="1"></a></p>
<p>For a begineer in R or any language,regular expression might seem like a daunting task . Rebus package in R gives a lowers the barrier for common regular expression tasks and is useful for a begineer or even for advanced users for most of the common regex skills in a more intuitive yet verbose way .Check out the package and try this exercises to test your knowledge .<br>
Load stringr/stringi as well for this set of exercise . I encourage you to do <a rel="nofollow" href="http://www.r-exercises.com/2017/07/14/hacking-strings-with-stringr/" target="_blank">this</a> and<br>
<a rel="nofollow" href="http://www.r-exercises.com/2017/07/28/hacking-strings-with-stringi/" target="_blank">this</a> before working on this set .<br>
Answers are available <a rel="nofollow" href="http://www.r-exercises.com/2017/08/11/more-string-hacking-with-regex-and-rebus-solution/" target="_blank">here</a>.</p>
<p>If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p><strong>Exercise 1</strong><br>
create two strings<br>
Suppose you have a vectore<br>
<code> x &lt;- c(&quot;stringer&quot;,&quot;stringi&quot;,&quot;rebus&quot;,&quot;redbus&quot;) </code> </p>
<p>use rebus and find the strings starting with st .Hint use START from rebus</p>
<p><strong>Exercise 2</strong></p>
<p>Use the same string vectore and find the strings which ends with bus. </p>
<p><strong>Exercise 3</strong><br>
you have a vector like<br>
<code> m &lt;-  c(&quot;aba&quot;,&quot;aca&quot;,&quot;abba&quot;,&quot;accdda&quot;)</code> </p>
<p>find the strings which starts and ends with a and have a single character in between<br>
Hint – use ANY_CHAR<br>
<strong>Exercise 4</strong><br>
<code> y &lt;- c(&quot;brain&quot;,&quot;brawn&quot;,&quot;rain&quot;,&quot;train&quot;) </code> </p>
<p>find all the strings that starts with br and ends with n .<br>
Hint – use any_char with hi=Inf to build the regex </p>
<div>
<aside><img src="http://www.r-exercises.com/2017/08/11/more-string-hacking-with-regex-and-rebus/"></aside>
<div><strong>Learn more</strong> about Text analysis in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/text-analyticstext-mining-using-r/" target="_blank">Text Analytics/Text Mining Using R</a>. In this course you will learn how create, analyse and finally visualize your text based data source. Having all the steps easily outlined will be a great reference source for future work.</div>
</div>
<p><strong>Exercise 5</strong><br>
Use the same vector as previous exercise and find strings starting with br or tr .<br>
Hint – or </p>
<p><strong>Exercise 6</strong><br>
Now we turn our attention to character class,if you are familiar with character classes in regex , you will find it pretty easy with rebus and if you are starting with regex .you might find it easy to remember with rebus<br>
Suppose you have a vector<br>
<code> l &lt;-  c(&quot;Canada&quot;,&quot;america&quot;,&quot;france&quot;) </code></p>
<p>Find string with C or m in it .so your answer should be Canada and America</p>
<p><strong>Exercise 7</strong><br>
From the string 123abc ,find the digits ,using rebus . </p>
<p><strong>Exercise 8</strong><br>
Create a character class for vowels and find all the Vowels in the vector<br>
<code> vow &lt;- c(&quot;blue&quot;,&quot;sue&quot;,&quot;CLUE&quot;,&quot;TRUE&quot;) </code></p>
<p><strong>Exercise 9</strong><br>
Find the characters other than vowels from above vector . </p>
<p><strong>Exercise 10</strong><br>
Now create a new vector<br>
<code> vow1 &lt;- c(&quot;blue&quot;,&quot;sue&quot;,&quot;CLUE&quot;,&quot;TRUE&quot;,&quot;aue&quot;)</code></p>
<p>find the string which is made of only vowels </p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/10/30/regular-expressions-part-1/" title="Regular Expressions Exercises – Part 1" target="_blank">Regular Expressions Exercises – Part 1 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/07/28/hacking-strings-with-stringi/" title="Hacking Strings with stringi" target="_blank">Hacking Strings with stringi </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/07/14/hacking-strings-with-stringr/" title="Hacking strings with stringr" target="_blank">Hacking strings with stringr </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/08/11/more-string-hacking-with-regex-and-rebus/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/jsyaQ94S_7c" height="1"></a></div>