<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>Capturing
</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="Composable F# regular expressions."/>
    <meta name="author" content="Jack Fox"/>

    <script src="https://code.jquery.com/jquery-1.8.0.js"></script>
    <script src="https://code.jquery.com/ui/1.8.23/jquery-ui.js"></script>
    <script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
    <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet"/>

    <link type="text/css" rel="stylesheet" href="/FsRegEx/content/style.css" />
    <script type="text/javascript" src="/FsRegEx/content/tips.js"></script>
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container">
      <div class="masthead">
        <ul class="nav nav-pills pull-right">
          <li><a href="http://fsharp.org">fsharp.org</a></li>
          <li><a href="https://github.com/jackfoxy/FsRegEx">github page</a></li>
        </ul>
        <h3 class="muted"><a href="/FsRegEx/index.html">FsRegEx</a></h3>
      </div>
      <hr />
      <div class="row">
        <div class="span9" id="main">
          
<h1><a name="Capturing" class="anchor" href="#Capturing">Capturing</a></h1>
<p>Capturing is a shortcut through matching to a named group or the group's captured value.</p>
<h3><a name="capture" class="anchor" href="#capture">capture</a></h3>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l">1: </span>
<span class="l">2: </span>
<span class="l">3: </span>
<span class="l">4: </span>
<span class="l">5: </span>
<span class="l">6: </span>
<span class="l">7: </span>
<span class="l">8: </span>
<span class="l">9: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">open</span> <span class="id">FsRegEx</span>

<span class="k">let</span> <span onmouseout="hideTip(event, 'fs1', 1)" onmouseover="showTip(event, 'fs1', 1)" class="id">groupNumberRegExp</span> <span class="o">=</span> <span class="s">@&quot;COD(?&lt;GroupNumber&gt;[0-9]{3})END&quot;</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs2', 2)" onmouseover="showTip(event, 'fs2', 2)" class="id">groupNumberName</span> <span class="o">=</span> <span class="s">&quot;GroupNumber&quot;</span>

<span class="id">capture</span> <span onmouseout="hideTip(event, 'fs1', 3)" onmouseover="showTip(event, 'fs1', 3)" class="id">groupNumberRegExp</span> <span onmouseout="hideTip(event, 'fs2', 4)" onmouseover="showTip(event, 'fs2', 4)" class="id">groupNumberName</span> <span class="s">&quot;COD123END&quot;</span>
<span class="o">|&gt;</span> <span onmouseout="hideTip(event, 'fs3', 5)" onmouseover="showTip(event, 'fs3', 5)" class="fn">printfn</span> <span class="s">&quot;</span><span class="pf">%s</span><span class="s">&quot;</span>

<span class="c">// 123</span>
</code></pre></td>
</tr>
</table>
<h3><a name="capture-group" class="anchor" href="#capture-group">capture group</a></h3>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l">1: </span>
<span class="l">2: </span>
<span class="l">3: </span>
<span class="l">4: </span>
<span class="l">5: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">let</span> <span onmouseout="hideTip(event, 'fs4', 6)" onmouseover="showTip(event, 'fs4', 6)" class="id">group</span> <span class="o">=</span> <span class="id">captureGroup</span> <span onmouseout="hideTip(event, 'fs1', 7)" onmouseover="showTip(event, 'fs1', 7)" class="id">groupNumberRegExp</span> <span onmouseout="hideTip(event, 'fs2', 8)" onmouseover="showTip(event, 'fs2', 8)" class="id">groupNumberName</span> <span class="s">&quot;COD123END&quot;</span>

<span onmouseout="hideTip(event, 'fs3', 9)" onmouseover="showTip(event, 'fs3', 9)" class="fn">printfn</span> <span class="s">&quot;</span><span class="pf">%s</span><span class="s">&quot;</span> <span onmouseout="hideTip(event, 'fs4', 10)" onmouseover="showTip(event, 'fs4', 10)" class="id">group</span><span class="pn">.</span><span class="id">Value</span>

<span class="c">// 123</span>
</code></pre></td>
</tr>
</table>

<div class="tip" id="fs1">val groupNumberRegExp : string</div>
<div class="tip" id="fs2">val groupNumberName : string</div>
<div class="tip" id="fs3">val printfn : format:Printf.TextWriterFormat&lt;&#39;T&gt; -&gt; &#39;T</div>
<div class="tip" id="fs4">val group : obj</div>

        </div>
        <div class="span3">
          <img src="/FsRegEx/img/logo.png" alt="F# Project" style="width:150px;margin:10px" />  
            <ul class="nav nav-list" id="menu" style="margin-top: 20px;">
                <li class="nav-header">FsRegEx</li>
                <li><a href="/FsRegEx/index.html">Home page</a></li>
                <li class="divider"></li>
                <li><a href="http://nuget.org/packages/FsRegEx">Get Library via NuGet</a></li>
                <li><a href="https://github.com/jackfoxy/FsRegEx">Source Code on GitHub</a></li>
                <li><a href="/FsRegEx/license.html">License</a></li>
                <li><a href="/FsRegEx/release-notes.html">Release Notes</a></li>

                <li class="nav-header">Examples</li>
                <li><a href="/FsRegEx/matching.html">Matching</a></li>
                <li><a href="/FsRegEx/group.html">Match Groups</a></li>
                <li><a href="/FsRegEx/replacesplit.html">Replace and Split</a></li>
                <li><a href="/FsRegEx/capture.html">Capture</a></li>

                <li class="nav-header">Documentation</li>
                <li><a href="/FsRegEx/reference/index.html">API Reference</a></li>

                <li class="nav-header">More...</li>
                <li><a href="/FsRegEx/emailregex.html">On the Futility of Email Regex Validation</a></li>
                <li><a href="/FsRegEx/tutorial.html">F# Verbal Expressions Tutorial</a></li>
            </ul>
        </div>
      </div>
    </div>
    <a href="https://github.com/jackfoxy/FsRegEx"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub"/></a>
  </body>
  </html>
