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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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 4</a></li>
   </ul>
   <div id="col-1-tab-1">
   <article>
    <h1>telephone number comparison</h1>
    <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="email-address"></textarea>
    </p>
    <p>
     <button id="tryit" class="tryit">try it</button>
    </p>
    <div class="discussion">
    <p>This is the same phone number you've seen before but the RegExp pattern syntax has been added for a direct comparison.</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;
  line-height: 100%;
  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;
}

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

#regexp-def {
	height: 5em;
}

#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 $regexp, $apgexp, $email, $regresult, $apgresult;

// main function, execute pattern search
var execute = function() {
  executeApgExp();
  executeRegExp();
}
var executeApgExp = function(){
  var exp, result, output;
  try {
    exp = new ApgExp($apgexp.val());
    result = exp.exec($email.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($regexp.val(), "i");
    result = exp.exec($email.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 with HTML <pre> block
var pre = function(text) {
  var ret = "<pre>\n";
  ret += text;
  ret += "</pre>";
  return ret;
}
$(document).ready(function() {
  
  // RegExp regular expression
  strings.regexp = "^\\(?(\\d{3})\\D{0,3}(\\d{3})\\D{0,3}(\\d{4})$";

  // SABNF pattern syntax
  strings.apgexp  = 'phone-number = %^ ["("] area-code sep office-code sep subscriber %$\n';
  strings.apgexp += 'area-code    = 3digit                       ; 3 digits\n';
  strings.apgexp += 'office-code  = 3digit                       ; 3 digits\n';
  strings.apgexp += 'subscriber   = 4digit                       ; 4 digits\n';
  strings.apgexp += 'sep          = *3(%d32-47 / %d58-126 / %d9) ; 0-3 ASCII non-digits\n';
  strings.apgexp += 'digit        = %d48-57                      ; 0-9\n';

  // initial value for input string
  strings.input = "(333)555-1234";
  
  // jQuery values
  $regexp = $("#regexp-def");
  $apgexp = $("#apgexp-def");
  $email = $("#email-address");
  $regresult = $("#regexp-result");
  $apgresult = $("#apgexp-result");

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

            
          
!
999px
Loading ..................

Console