Regex Tester

Test a regex against multiple inputs simultaneously.

HTML

<input id=regex placeholder=regex value="((https|http)://)*[A-z0-9.-~-]+((/([\/\w\d\-?=\.])*)|(?=\s))" />

<div id=cols>
<textarea id=input placeholder=inputs>http://google/test
http://google/test

BRap.fm
[email protected] Thank you!

...can't stay
acom.com/.html
bca.com

www.iplt20.com site 

http://199.12.129.100/petgrp/

http://abc-xyz/obic7fxkm/
http://able-s-wfweb/~bd/pc.php/login
http://199.12.109.100:8888/umvis/
https://test.ex.com/ma/rasdf/</textarea>
<textarea id=output disabled></textarea>
</div>

CSS

#regex {
  width: 100%;
  display: block;
}

#cols {
  padding: 0 50px 0 0;
  position: relative;
}

#input {
  width: 100%;
  height: 20em;
}

#output {
  position: absolute;
  width: 600px;
  height: 20em;
  right: 0;
  top: 0;
}

JavaScript

function update() {
  var regex = $('#regex').val();
  
  // Allow for /blah/ syntax or simply blah syntax
  if (regex.charAt(0) == '/')
    regex = regex.substr(1);
  if (regex.charAt(regex.length - 1) == '/')
    regex = regex.substr(0, regex.length - 1);
  
  regex = new RegExp(regex);
  
  var input = $('#input').val()
    .replace('\r', '')
    .split('\n');
  
  var output = $.map(input, function(text) {
    if (text != ''){
      response = regex.test(text) ? 'true' : 'false';
      return "=>"+text+" :: "+response;
    }
    else{
      return "              ";
    }
  });
  
  $('#output').val(output.join('\n'));
};

$('#regex, #input').keyup(update).click(update);