cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
               <div id="css-table">
  <div id="col-1">
   <ul>
    <li><a href="#col-1-tab-1">Example 1</a></li>
   </ul>
   <div id="col-1-tab-1">
   <article>
    <h1>email address</h1>
    <p class="title">
     <b>RegExp:</b>
       </p>
    <textarea class="input" id="regexp-def" disabled></textarea>
    </p>
    <p>
     <p class="title"><b>apg-exp:</b>
    </p>
    <textarea class="input" id="apgexp-def" disabled></textarea>
    </p>
      <p class="title"><b>email address:</b>
    </p>
     <textarea class="input" id="email-address"></textarea>
    </p>
    <p>
     <button id="tryit" class="tryit">try it</button>
    </p>
   </div>
   </article>
  </div>
  <div id="col-2">
   <ul>
    <li><a href="#col-2-tab-1">apg-exp</a></li>
   </ul>
   <div id="col-2-tab-1">
   <article>
    <p>
     All phrases captured by all rules are retained along with the index to the first letter where the capture was found. Display of the character
     rules,
     <code>local-char, sub-domain-char, top-domain-char, alpha, num & special</code>
     has been suppressed for clarity. Note that the first rule in the syntax always defines the full phrase to be matched.
     <code>result[0]</code>
     is simply an alias for compatibility with RegExp.
    </p>
    <div id="pattern-note">
    <p>
    <i><b>Note:</b> First-time users
    are often unclear about how, exactly, that big, multi-line ABNF pattern syntax is introduced into the <b>apg-exp</b> object.
    The short answer is, exactly the same way that a regular expression is introduced into the RegExp object.
    It is passed into the constructor as a single string.
    </p>
    <pre>
var exp = new ApgExp(pattern);
</pre>
    The only difference between this and constructing a RegExp object is that the pattern is a multi-line string.
    The ABNF named rules must be on separate lines and end with a newline (continuation lines begin with a space or tab).
    <ul>
    <li>
    In a web application, the pattern is often read from a textarea, as is done in this example (see the function <code>executeApgExp()</code>).
    </li>
    <li>
    In a desktop setting, the pattern is often read from a multi-line text file.
    </li>
    <li>
    For simple patterns or quick testing they might simply be introduced as a constructed string:
    <pre>
var pattern = "";
pattern += 'email-address = %^ local "@" domain %$\n';
pattern += 'local = local-word *("." local-word)\n';
  ...
</pre>
    </li>
    </ul></i>
    </div>
    <div id="apgexp-result"></div>
   </div>
   </article>
  </div>
  <div id="col-3">
   <ul>
    <li><a href="#col-3-tab-1">RegExp</a></li>
   </ul>
   <div id="col-3-tab-1">
   <article>
    <p>
     This syntax is taken from the <a class="link" href="http://www.amazon.com/Regular-Expressions-Cookbook-Jan-Goyvaerts/dp/1449319432">
      <i>Regular Expressions Cookbook</i>
     </a> by Goyvaerts and Levithan, pg. 245. Some groupings have been added to capture the local and domain parts (
     <code>result[1]</code> & <code>result[4]</code>, respectively) and the local, sub-domain and top-domain words.
     In the case where a single group captures more than one phrase, only the last capture is retained.
     This can be seen in this example with the "local word" and "sub domain" groups,
     <code>result[3]</code> & <code>result[5]</code>, respectively.
     </p>
     <p>
     Note that many
     <a class="link" href="http://www.regular-expressions.info/tools.html">other languages</a> offer more features
     and even with RegExp there are <a class="link" href="http://xregexp.com/">good tools</a> for easier use, more features and <a
      class="link" href="https://www.regexbuddy.com/">debugging help</a>.
      But with native JavaScript RegExp, this is about all you get.
    </p>
    <div id="regexp-result"></div>
   </article>
   </div>
  </div>
 </div>

            
          
!
            
              /* Pen-specific styles */
* {
  box-sizing: border-box;
}

body {
  color: #000;
  font-size: .8rem;
  line-height: 150%;
}

h1 {
  font-size: 1.75rem;
  margin: 0 0 0.75rem 0;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700;
}

h2 {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700;
}

article {
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
}

b {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700;
}

i {
  font-family: 'Open Sans', sans-serif;
  font-style: italic;
}

textarea {
  width: 100%;
}

button {
  cursor: pointer;
  cursor: hand;
}

p.title {
  margin: 0px 0px 3px 0px;
}

a.link {
  color: #4284B0;
}

a.link:visited {
  color: #9c4be7;
}

/* Pattern styles */
#css-table {
	display: table;
}

#col-1 {
	display: table-cell;
	width: 30%;
	border: 1px solid #4284B0;
}

#col-2 {
	display: table-cell;
	width: 35%;
	border-width: 1px 0px;
	border-style: solid;
	border-color: #4284B0;
}

#col-3 {
	display: table-cell;
	width: 35%;
	border: 1px solid #4284B0;
}

textarea.input {
	font-size: .9rem;
	font-family: monospace;
}

pre{
  font-size: .9rem;
  font-family: monospace;
  line-height: 100%;
}

#regexp-def, #apgexp-def, #email-address {
	width: 95%;
}

#regexp-def {
	height: 5em;
}

#apgexp-def {
	height: 20em;
}

.tryit {
	font-size: 1em;
	width: 5rem;
	cursor: pointer;
	cursor: hand;
}

.discussion {
	display: inline;
	font-size: .9rem;
	line-height: 125%;
}

.title {
	margin: .25rem 0;
}

div#pattern-note{
	font-size: .9em;
	line-height: 1.1em;
}
            
          
!
            
              //main function
var execute = function() {
  executeApgExp();
  executeRegExp();
}

// execute apg-exp
var executeApgExp = function(){
  var exp, result, output;
  exp = new ApgExp($("#apgexp-def").val());
  exp.exclude([ "local-char", "sub-domain-char", "top-domain-char", "alpha", "num", "special" ]);
  result = exp.exec($("#email-address").val());
  if (result) {
    output = result.toHtml();
  } else {
    output = "<pre>\n";
    output += "result: null";
    output += "</pre>\n";
  }
  $("#apgexp-result").html(output);
}

//execute RegExp
var executeRegExp = function(){
  var exp, result, output;
  exp = new RegExp($("#regexp-def").val(), "i");
  result = exp.exec($("#email-address").val());
  if (result) {
    output = regToHtml(result);
  } else {
    output = "<pre>\n";
    output += "result: null";
    output += "</pre>\n";
  }
  $("#regexp-result").html(output);
}

// format RegExp result to HTML table
var regToHtml = function(result) {
  var html = "";
  var caption = "result:";
  html += '<table class="apg-left-table">\n';
  html += '<caption>' + caption + '</caption>\n';
  html += '<tr>';
  html += '<td>input</td>';
  html += '<td>' + result.input + '</td>';
  html += '</tr>\n';

  html += '<tr>';
  html += '<td>index</td>';
  html += '<td>' + result.index + '</td>';
  html += '</tr>\n';

  for (var i = 0; i < result.length; i += 1) {
    html += '<tr>';
    html += '<td>[' + i + ']</td>';
    html += '<td>' + result[i] + '</td>';
    html += '</tr>\n';
  }
  html += '</table>\n';
  return html;
}

$(document).ready(function() {
  var string = {};
  
  // RegExp - regular expression syntax
  string.regexp = "^(([\\w!#$%&'*+/=?^_`{|}~-]+)(?:\\.([\\w!#$%&'*+/=?^_`{|}~-]+))*)@((?:([A-Z0-9-]+)\\.)+([A-Z]{2,6}))$";

  // ApgExp - ABNF syntax
  string.apgexp = "";
  string.apgexp += 'email-address   = %^ local "@" domain %$\n';
  string.apgexp += 'local           = local-word *("." local-word)\n';
  string.apgexp += 'domain          = 1*(sub-domain ".") top-domain\n';
  string.apgexp += 'local-word      = 1*local-char\n';
  string.apgexp += 'sub-domain      = 1*sub-domain-char\n';
  string.apgexp += 'top-domain      = 2*6top-domain-char\n';
  string.apgexp += 'local-char      = alpha / num / special\n';
  string.apgexp += 'sub-domain-char = alpha / num / "-"\n';
  string.apgexp += 'top-domain-char = alpha\n';
  string.apgexp += 'alpha           = %d65-90 / %d97-122\n';
  string.apgexp += 'num             = %d48-57\n';
  string.apgexp += 'special         = %d33      / %d35 / %d36-39\n';
  string.apgexp += '                  / %d42-43 / %d45 / %d47\n';
  string.apgexp += '                  / %d61    / %d63 / %d94-96\n';
  string.apgexp += '                  / %d123-126\n';

  // initial email address
  string.input= 'foo.b.bar@my.email.com';

  // page setup
  $("#col-1").tabs();
  $("#col-2").tabs();
  $("#col-3").tabs();
  $("#regexp-def").val(string.regexp)
  $("#apgexp-def").val(string.apgexp)
  $("#email-address").val(string.input)
  $("#tryit").click(execute);
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console