<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">Regular expressions – Haskell – Aelve Guide</title><id>https://guide.aelve.com/haskell/feed/category/jf3ju3u2</id><updated>2016-08-21T22:59:44Z</updated><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/feed/category/jf3ju3u2"/><entry><id>b9j0hxi9</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-type</title><updated>2016-08-21T22:59:44Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-type&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-type&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-b9j0hxi9"/></entry><entry><id>azxhk1pp</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">relit</title><updated>2016-04-09T14:08:28Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;relit&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/relit&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Not a library, but a quasiquoter for various &lt;code&gt;regex*&lt;/code&gt; libraries.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-azxhk1pp"/></entry><entry><id>tzjxzagz</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-pderiv</title><updated>2016-04-09T14:08:20Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-pderiv&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-pderiv&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-tzjxzagz"/></entry><entry><id>cy31mlzz</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-posix</title><updated>2016-04-09T14:07:23Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-posix&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-posix&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;The library is bundled.&lt;/p&gt;
&lt;p&gt;Regex flavor: POSIX.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/lens-regex&#34;&gt;lens-regex&lt;/a&gt;&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-cy31mlzz"/></entry><entry><id>vpcicemu</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-pcre</title><updated>2016-04-09T14:06:22Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-pcre&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-pcre&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Uses system PCRE library.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-vpcicemu"/></entry><entry><id>s6qidbvw</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-pcre-builtin</title><updated>2016-04-09T14:06:15Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-pcre-builtin&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-pcre-builtin&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Regex flavor: PCRE.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/pcre-utils&#34;&gt;pcre-utils&lt;/a&gt; – provides split/replace&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-s6qidbvw"/></entry><entry><id>n0057uwj</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-tdfa</title><updated>2016-04-09T14:03:31Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-tdfa&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-tdfa&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Uses &lt;a href=&#34;https://hackage.haskell.org/package/regex-base&#34;&gt;regex-base&lt;/a&gt;. Seems to be the most popular library.&lt;/p&gt;
&lt;p&gt;Regex flavor: POSIX.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Handles corner cases &lt;a href=&#34;https://wiki.haskell.org/Regex_Posix&#34;&gt;better&lt;/a&gt; than other POSIX implementations (including glibc and the rest).&lt;/li&gt;&lt;/p&gt;&lt;p&gt;&lt;li&gt;Doesn&#39;t require any installed libraries (since it&#39;s written in pure Haskell).&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Slightly complicated to use, and documentation isn&#39;t particularly good.&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regex-tdfa-pipes&#34;&gt;regex-tdfa-pipes&lt;/a&gt;, &lt;a href=&#34;https://hackage.haskell.org/package/regex-tdfa-quasiquoter&#34;&gt;regex-tdfa-quasiquoter&lt;/a&gt;, &lt;a href=&#34;https://hackage.haskell.org/package/regex-tdfa-text&#34;&gt;regex-tdfa-text&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regex-genex&#34;&gt;regex-genex&lt;/a&gt; can generate all strings matching some regex, and &lt;a href=&#34;https://hackage.haskell.org/package/quickcheck-regex&#34;&gt;quickcheck-regex&lt;/a&gt; can use that to generate test cases for Quickcheck&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regex-compat-tdfa&#34;&gt;regex-compat-tdfa&lt;/a&gt; is a wrapper over regex-tdfa with a simple interface&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-n0057uwj"/></entry><entry><id>prhw67xd</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regexpr</title><updated>2016-04-09T14:01:52Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regexpr&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regexpr&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-prhw67xd"/></entry><entry><id>w6kin9fk</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regex-applicative</title><updated>2016-04-09T14:00:50Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regex-applicative&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regex-applicative&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Regex-like parsing combinators.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/lexer-applicative&#34;&gt;lexer-applicative&lt;/a&gt;, &lt;a href=&#34;https://hackage.haskell.org/package/regex-applicative-text&#34;&gt;regex-applicative-text&lt;/a&gt;&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-w6kin9fk"/></entry><entry><id>szrn6x33</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">weighted-regexp</title><updated>2016-04-09T13:59:17Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;weighted-regexp&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/weighted-regexp&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;See &lt;a href=&#34;http://sebfisch.github.io/haskell-regexp&#34;&gt;http://sebfisch.github.io/haskell-regexp&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regexp-tries&#34;&gt;regexp-tries&lt;/a&gt;&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-szrn6x33"/></entry><entry><id>w9lymolv</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">hxt-regex-xmlschema</title><updated>2016-04-09T13:59:05Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;hxt-regex-xmlschema&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/hxt-regex-xmlschema&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-w9lymolv"/></entry><entry><id>ljx3hkhb</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">re2</title><updated>2016-04-09T13:56:56Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;re2&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/re2&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Bindings to Google&#39;s RE2 library.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-ljx3hkhb"/></entry><entry><id>x754lm90</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">regexdot</title><updated>2016-04-09T13:55:09Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;regexdot&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/regexdot&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Regex flavor: POSIX.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Works on lists of arbitrary objects.&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regexchar&#34;&gt;regexchar&lt;/a&gt;&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-x754lm90"/></entry><entry><id>ykbn4lid</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">pcre-light</title><updated>2016-04-09T13:46:23Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;pcre-light&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/pcre-light&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Binds to the C PCRE library.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Only works with bytestrings unless you use a wrapper.&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://hackage.haskell.org/package/regex-easy&#34;&gt;regex-easy&lt;/a&gt; – a convenience wrapper (TODO: probably useless?)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hackage.haskell.org/package/pcre-heavy&#34;&gt;pcre-heavy&lt;/a&gt; – another convenience wrapper&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hackage.haskell.org/package/rex&#34;&gt;rex&lt;/a&gt; – quasiquoter&lt;/li&gt;
&lt;/ul&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-ykbn4lid"/></entry><entry><id>n2ri8dzx</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">text-icu</title><updated>2016-04-03T09:50:05Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;text-icu&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/text-icu&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Bindings to &lt;a href=&#34;http://site.icu-project.org/&#34;&gt;International Components for Unicode&lt;/a&gt;, which among other things provides regexes. See &lt;a href=&#34;https://hackage.haskell.org/package/text-icu/docs/Data-Text-ICU.html#g:10&#34;&gt;this section&lt;/a&gt; of the &lt;code&gt;Data.Text.ICU&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;Regex flavor: PCRE.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Supports Unicode classes – e.g. &lt;code&gt;[:lower:]&lt;/code&gt; matches all lowercase letters, not just Latin ones.&lt;/li&gt;&lt;/p&gt;&lt;p&gt;&lt;li&gt;Allows limiting time/memory used by the matcher.&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Cons&lt;/h2&gt;&lt;ul&gt;&lt;p&gt;&lt;li&gt;Requires &lt;a href=&#34;http://site.icu-project.org/&#34;&gt;ICU&lt;/a&gt; installed.&lt;/li&gt;&lt;/p&gt;&lt;/ul&gt;&lt;h2&gt;Ecosystem&lt;/h2&gt;&lt;p&gt;&lt;a href=&#34;https://hackage.haskell.org/package/text-regex-replace&#34;&gt;text-regex-replace&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Notes&lt;/h2&gt;&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-links&#34;&gt;&lt;/span&gt;Links&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://userguide.icu-project.org/strings/regexp#TOC-Regular-Expression-Metacharacters&#34;&gt;Documentation on ICU regular expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hackage.haskell.org/package/text-icu/docs/Data-Text-ICU.html#g:10&#34;&gt;Documentation on the part of the library that deals with regular expressions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-imports-and-pragmas&#34;&gt;&lt;/span&gt;Imports and pragmas&lt;/h1&gt;&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;ot&#34;&gt;{-# LANGUAGE OverloadedStrings #-}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It&#39;s better to import the module qualified, because some functions from it (like &lt;code&gt;find&lt;/code&gt; and &lt;code&gt;span&lt;/code&gt;) clash with those from Prelude. Additionally, many functions clash with ones from &lt;code&gt;Data.Text&lt;/code&gt;, so don&#39;t import it as &lt;code&gt;T&lt;/code&gt; either.&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;kw&#34;&gt;import qualified&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Data.Text.ICU&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;ICU&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want replacement as well:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;co&#34;&gt;-- from text-regex-replace&lt;/span&gt;
&lt;span class=&#34;kw&#34;&gt;import qualified&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Data.Text.ICU.Replace&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;ICU&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-search&#34;&gt;&lt;/span&gt;Search&lt;/h1&gt;&lt;p&gt;To search, use &lt;code&gt;findAll&lt;/code&gt; (or &lt;code&gt;find&lt;/code&gt; if you only need the 1st match):&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.findAll &lt;span class=&#34;st&#34;&gt;&amp;quot;[0-9]+&amp;quot;&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;12 + 34 = 55&amp;quot;&lt;/span&gt;
[&lt;span class=&#34;dt&#34;&gt;Match&lt;/span&gt; [&lt;span class=&#34;st&#34;&gt;&amp;quot;12&amp;quot;&lt;/span&gt;],&lt;span class=&#34;dt&#34;&gt;Match&lt;/span&gt; [&lt;span class=&#34;st&#34;&gt;&amp;quot;34&amp;quot;&lt;/span&gt;],&lt;span class=&#34;dt&#34;&gt;Match&lt;/span&gt; [&lt;span class=&#34;st&#34;&gt;&amp;quot;55&amp;quot;&lt;/span&gt;]]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;findAll&lt;/code&gt; returns a list of &lt;code&gt;Match&lt;/code&gt;es. A &lt;code&gt;Match&lt;/code&gt; holds information about the matched piece of text, groups inside of the match, and text occuring between the matches.&lt;/p&gt;
&lt;p&gt;For example, let&#39;s construct a regex that would match a name and a surname: &lt;code&gt;(\p{Lu}\w*) (\p{Lu}\w*)&lt;/code&gt; – here &lt;code&gt;\w&lt;/code&gt; means “character that can occur inside a word”, and &lt;code&gt;\p{Lu}&lt;/code&gt; means “character from Unicode category &lt;code&gt;Lu&lt;/code&gt;”, which is “Letter, uppercase”:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;let&lt;/span&gt; regex &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;(\\p{Lu}\\w*) (\\p{Lu}\\w*)&amp;quot;&lt;/span&gt;
&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;let&lt;/span&gt; [zaphod, ford] &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; ICU.findAll regex &lt;span class=&#34;st&#34;&gt;&amp;quot;Zaphod Beeblebrox and Ford Prefect&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To get the match itself, use &lt;code&gt;group 0&lt;/code&gt; (which will always return &lt;code&gt;Just&lt;/code&gt;, but unfortunately the library doesn&#39;t provide an easier way to get the match without having to unwrap &lt;code&gt;Just&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.group &lt;span class=&#34;dv&#34;&gt;0&lt;/span&gt; ford
&lt;span class=&#34;dt&#34;&gt;Just&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;Ford Prefect&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can also use &lt;code&gt;group&lt;/code&gt; to get a particular capturing group:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.group &lt;span class=&#34;dv&#34;&gt;1&lt;/span&gt; ford
&lt;span class=&#34;dt&#34;&gt;Just&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;Ford&amp;quot;&lt;/span&gt;

&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.group &lt;span class=&#34;dv&#34;&gt;2&lt;/span&gt; ford
&lt;span class=&#34;dt&#34;&gt;Just&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;Prefect&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;span&lt;/code&gt; returns the text between the previous match and this match:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.span ford
&lt;span class=&#34;st&#34;&gt;&amp;quot; and &amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally, you can use &lt;code&gt;prefix&lt;/code&gt; and &lt;code&gt;suffix&lt;/code&gt; to get the whole string before/after the match:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.prefix &lt;span class=&#34;dv&#34;&gt;0&lt;/span&gt; ford
&lt;span class=&#34;dt&#34;&gt;Just&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;Zaphod Beeblebrox and &amp;quot;&lt;/span&gt;

&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.suffix &lt;span class=&#34;dv&#34;&gt;0&lt;/span&gt; ford
&lt;span class=&#34;dt&#34;&gt;Just&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-replacement&#34;&gt;&lt;/span&gt;Replacement&lt;/h1&gt;&lt;p&gt;Simple replacement is done with &lt;code&gt;replaceAll&lt;/code&gt; (to replace only the 1st match, use &lt;code&gt;replace&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.replaceAll &lt;span class=&#34;st&#34;&gt;&amp;quot;[0-9]+&amp;quot;&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;&amp;lt;num&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;12 + 34 = 55&amp;quot;&lt;/span&gt;
&lt;span class=&#34;st&#34;&gt;&amp;quot;&amp;lt;num&amp;gt; + &amp;lt;num&amp;gt; = &amp;lt;num&amp;gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Replacement with groups:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; ICU.replaceAll &lt;span class=&#34;st&#34;&gt;&amp;quot;(.*), (.*)&amp;quot;&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;$2 $1&amp;quot;&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;Beeblebrox, Zaphod&amp;quot;&lt;/span&gt;
&lt;span class=&#34;st&#34;&gt;&amp;quot;Zaphod Beeblebrox&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;(To have a literal &lt;code&gt;$&lt;/code&gt; in the output, write &lt;code&gt;$$&lt;/code&gt; instead of &lt;code&gt;$&lt;/code&gt;.)&lt;/p&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-splitting&#34;&gt;&lt;/span&gt;Splitting&lt;/h1&gt;&lt;p&gt;text-icu doesn&#39;t export a splitting function, which makes it a bit complicated. Here&#39;s one that you could use:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;ot&#34;&gt;split ::&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;ICU.Regex&lt;/span&gt; &lt;span class=&#34;ot&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Text&lt;/span&gt; &lt;span class=&#34;ot&#34;&gt;-&amp;gt;&lt;/span&gt; [&lt;span class=&#34;dt&#34;&gt;Text&lt;/span&gt;]
split r s &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; go (ICU.findAll r s)
  &lt;span class=&#34;kw&#34;&gt;where&lt;/span&gt; go [] &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; [s]
        go [m] &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; [ICU.span m, fromJust (ICU.suffix &lt;span class=&#34;dv&#34;&gt;0&lt;/span&gt; m)]
        go (m&lt;span class=&#34;fu&#34;&gt;:&lt;/span&gt;ms) &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; ICU.span m &lt;span class=&#34;fu&#34;&gt;:&lt;/span&gt; go ms&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-n2ri8dzx-regex-settings&#34;&gt;&lt;/span&gt;Regex settings&lt;/h1&gt;&lt;p&gt;You can customise the way regexes are applied by using &lt;code&gt;regex&lt;/code&gt; and &lt;a href=&#34;https://hackage.haskell.org/package/text-icu/docs/Data-Text-ICU.html#t:MatchOption&#34;&gt;&lt;code&gt;MatchOption&lt;/code&gt;&lt;/a&gt;. For instance, if you want the matching to be case-insensitive, use &lt;code&gt;CaseInsensitive&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode repl&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;let&lt;/span&gt; regex &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; ICU.regex [&lt;span class=&#34;dt&#34;&gt;ICU.CaseInsensitive&lt;/span&gt;] &lt;span class=&#34;st&#34;&gt;&amp;quot;xxx_(\\w+)_xxx&amp;quot;&lt;/span&gt;
&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;kw&#34;&gt;let&lt;/span&gt; str &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;quot;xxx_Overlord_xxx XXX_dp_ak_XXX&amp;quot;&lt;/span&gt;

&lt;span class=&#34;fu&#34;&gt;&amp;gt;&lt;/span&gt; mapMaybe (ICU.group &lt;span class=&#34;dv&#34;&gt;1&lt;/span&gt;) (ICU.findAll regex str)
[&lt;span class=&#34;st&#34;&gt;&amp;quot;Overlord&amp;quot;&lt;/span&gt;,&lt;span class=&#34;st&#34;&gt;&amp;quot;dp_ak&amp;quot;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There are other settings available – look at the docs for &lt;a href=&#34;https://hackage.haskell.org/package/text-icu/docs/Data-Text-ICU.html#t:MatchOption&#34;&gt;&lt;code&gt;MatchOption&lt;/code&gt;&lt;/a&gt; to see the full list.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/regular-expressions-jf3ju3u2#item-n2ri8dzx"/></entry></feed>