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 5</a></li>
   </ul>
   <div id="col-1-tab-1">
   <article>
    <h1>dates</h1>
    <p>
    Date requirements:<pre>
mm/dd/yy or mm/dd/yyyy
dd/mm/yy or dd/mm/yyyy
mm, 1-12 or 01-12, i.e. with or without leading zero
dd, 1-31 or 01-31, i.e. with or without leading zero
yy, 00-99
yyyy, 1900-1999 or 2000-2099    
</pre>
    </p>
    <pclass="title"><b>RegExp:</b><br>
    <textarea class="input" id="regexp-def"></textarea>
    </p>
    <p>
     <p class="title"><b>apg-exp:</b>
    </p>
    <textarea class="input" id="apgexp-def"></textarea>
    </p>
      <p class="title"><b>input string:</b>
    </p>
     <textarea class="input" id="input-string"></textarea>
    </p>
    <p>
     <button id="tryit" class="tryit">try it</button>
    </p>
    <div class="discussion">
    <p>
    While <b>apg-exp</b> does give a little more information in the result object,
    these two pattern matching syntaxes and tools perform nearly the same
    job for this problem.
    The biggest difference is in the readability of the pattern syntax.
    </p>
    </div>
   </article>
  </div>
  </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>
    <div id="apgexp-result"></div>
   </article>
  </div>
  </div>
  <div id="col-3">
   <ul>
    <li><a href="#col-3-tab-1">RegExp</a></li>
   </ul>
   <div id="col-3-tab-1">
   <article>
    <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;
	width: 100%;
}

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

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

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

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

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

#regexp-def {
	height: 6em;
}

#apgexp-def {
	height: 19em;
}

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

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

.title {
	margin: .25rem 0;
}
            
          
!
            
              var strings = {};
var $apgresult, $regresult, $data, $regdef, $apgdef;

// main function executes pattern matching searches
var execute = function() {
  executeApgExp();
  executeRegExp();
}
var executeApgExp = function(){
  var exp, result, output;
  try {
    exp = new ApgExp($apgdef.val());
    result = exp.exec($data.val());
    if (result) {
      output = result.toHtml();
    } else {
      output = "result: null\n";
      output = pre(output);
    }
  } catch (e) {
    if (e.name === "ApgExpError") {
      output = e.toHtml();
    } else if(e instanceof Error){
      output = "Error:\n";
      output += e.message;
      output = pre(output);
    }else{
      output = "unrecognized exception error:\n";
      output += e;
      output = pre(output);
    }
  }
  $apgresult.html(output);
}
var executeRegExp = function(){
  var exp, result, output;
  try {
    exp = new RegExp($regdef.val(), "i");
    result = exp.exec($data.val());
    if (result) {
      output = regToHtml(result);
    } else {
      output = pre("result: null");
    }
  } catch (e) {
    if(e instanceof Error){
      output = "RegExp syntax error: Error\n";
      output += e.message;
      output = pre(output);
    }else{
      output = "unrecognized exception error:\n";
      output += e;
      output = pre(output);
    }
  }
  $regresult.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;
}

// format text to HTML <pre> block
var pre = function(text) {
  var ret = "<pre>\n";
  ret += text;
  ret += "</pre>";
  return ret;
}
$(document).ready(function() {
  
  // RegExp regular expression syntax
  strings.regexp = "^(?:((?:0[1-9])|(?:1[0-2])|(?:[1-9]))/((?:0[1-9])|(?:(?:1|2)[0-9])|(?:3[0-1])|(?:[1-9]))|((?:0[1-9])|(?:(?:1|2)[0-9])|(?:3[0-1])|(?:[1-9]))/((?:0[1-9])|(?:1[0-2])|(?:[1-9])))/((?:19|20)?[0-9][0-9])$";

  // SABNF pattern syntax
  strings.apgexp = "";
  strings.apgexp += 'date     = %^ (mm-first / dd-first) %$\n';
  strings.apgexp += 'mm-first = mm "/" dd "/" yyyy   ; month before day\n';
  strings.apgexp += 'dd-first = dd "/" mm "/" yyyy   ; day before month\n';
  strings.apgexp += 'dd       = "0" digit1           ; 01-09\n';
  strings.apgexp += '         / ("1"/"2") digit      ; 10-29\n';
  strings.apgexp += '         / "3" %d48-49          ; 30-31\n';
  strings.apgexp += '         / digit1               ; 1-9\n';
  strings.apgexp += 'mm       = "0" digit1           ; 01-09\n';
  strings.apgexp += '         / "1" %d48-50          ; 10-12\n';
  strings.apgexp += '         / digit1               ; 1-9\n';
  strings.apgexp += 'yyyy     = ("19" / "20") 2digit ; 1900-1999 or 2000-2099\n';
  strings.apgexp += '         / 2digit               ; or 00-99\n';
  strings.apgexp += 'digit    = %d48-57              ; 0-9\n';
  strings.apgexp += 'digit1   = %d49-57              ; 1-9\n';
  
  // initial input string
  strings.input = "12/31/1959";

  // jQuery values
  $regdef = $("#regexp-def");
  $apgdef = $("#apgexp-def");
  $data = $("#input-string");
  $apgresult = $("#apgexp-result");
  $regresult = $("#regexp-result");

  // page setup
  $("#col-1").tabs();
  $("#col-2").tabs();
  $("#col-3").tabs();
  $regdef.val(strings.regexp)
  $apgdef.val(strings.apgexp)
  $data.val(strings.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