Commit 2840e9fb authored by Pouya Kary's avatar Pouya Kary

added example for start/end of line

parent 8d00b2a7
This diff is collapsed.
This diff is collapsed.
......@@ -632,6 +632,7 @@
<!-- Start of Line Character -->
<div class="separator"></div>
<div id="ref-sigma_range"></div>
<div class="row" id="ref-line_start">
<div class="column text">
<h2>Start of the Line</h2>
......@@ -646,12 +647,36 @@
<img src="blocks/start-of-line.svg">
</div>
</div>
<div class="row">
<div class="column text">
<h3>Example</h3>
A very common use of <b>Start of the Line</b> and <b>End of the Line</b> is when you want to exactly match a RegExp within your test sample. For example imagine if your test sample is <code>"aaabbbbaaa"</code> and your RegExp is the one you see in the right; What you want is to see if your string is only made of <code>a</code>.<br><br>
In JavaScript you would do <code>/a+/.test("aaabbbbaaa")</code> to test your string against the RegExp that we just made, result is however not what you expect, it is <code>true</code>.<br><br>
That simply is due to the fact that RegExp test functions <b>"Match Partially"</b> within your code so in this string there are two sequences containing a row of <code>a</code> characters and therefore RegExp engines returns <code>true</code>.
</div>
<div class="column block">
<img src="blocks/ex-start-end-of-line-1.svg">
</div>
</div>
<div class="row">
<div class="column text">
To overcome this problem you may use <b>Start of the Line</b> and <b>End of the Line</b> to indicate that you want <i>the whole string</i> to be match with your RegExp and not only a partial part of it.<br><br>
This Orchestra that compiles to <code>/^a+$/</code> ensures that your Orchestra is testing the full string and so it's result when testing <code>aaabbbbaaa</code> is <code>false</code>.
</div>
<div class="column block">
<img src="blocks/ex-start-end-of-line-2.svg">
</div>
</div>
<!-- End of Line Character -->
<div class="separator"></div>
<div class="row" id="ref-line_end">
<div class="row">
<div class="column text">
<h2>End of the Line</h2>
<p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment