JavaScript appears to be disabled. We recommend you enable JavaScript while visiting this site.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Regular Expression tester - JavaScript

In a previous post, I posted the code I used for a ColdFusion regular expression tester.

This time I've got an attempt at a JavaScript version. There's a number of TODOs, but ...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>JavaScript Regular Expression Tester</title>
<style type="text/css">
 #form_help {
  float:right;
  font-size:.8em;
  width:50%;
 }
 #form_results {
  margin:1em;
  width:45%;
 }
 .highlight {
  background-color:#ff9;
 }
 #form_highlighttext {
  border:1px dashed #ccc;
  margin-left:1em;
  width:45%;
 }
</style>
<script type="text/javascript">
 function RemoveHTML(TextContent) {
  var str = '';
  str = TextContent;
  str = str.replace(/</g, "&lt;");
  
  return str;
 }
 function TestExpression() {
  var Expression = '';
  var ExpressionParameters = 'gm';
  var ExpressionText = '';
  try {
   document.getElementById('form_error').innerHTML = '';
   document.getElementById('form_results').innerHTML = '';
   document.getElementById('form_highlighttext').innerHTML = '';
   if (document.getElementById('InputExpression').value != '' && document.getElementById('InputText').value != '') {
    // TODO better check and error writing - use span with _s
    if (document.getElementById('CheckCase').checked) {
     ExpressionParameters += 'i';
    }
    Expression = document.getElementById('InputExpression').value;
    ExpressionText = document.getElementById('InputText').value;
    var ExpressionObject = new RegExp(Expression, ExpressionParameters);
    var ExpressionTest = ExpressionObject.test(ExpressionText);
    if (ExpressionTest == true) {
     document.getElementById('form_results').innerHTML = '<p>The following results were found for your search:</p>';
     // Testing it appears to run it, so ...
     ExpressionObject = new RegExp(Expression, ExpressionParameters);
     var StringPosition = 0;
     var LastPosition = 0;
     var CountResults = 0;
     var ExpressionResults = ExpressionObject.exec(ExpressionText);
     if (ExpressionObject.global) {
      while (ExpressionResults != null) {
       document.getElementById('form_results').innerHTML += '' + RemoveHTML(ExpressionResults[0]) + ' (' + ExpressionResults.index + ' - ' + ExpressionObject.lastIndex + ')' + '<br />';
       if (CountResults == 0) {
        StringPosition = 0;
       } else {
        StringPosition = LastPosition;
       }
       document.getElementById('form_highlighttext').innerHTML += RemoveHTML(ExpressionText.substring(StringPosition, ExpressionResults.index)) + '<span class="highlight">' + RemoveHTML(ExpressionText.substring(ExpressionResults.index, ExpressionObject.lastIndex)) + '</span>';
       LastPosition = ExpressionObject.lastIndex;
       ExpressionResults = ExpressionObject.exec(ExpressionText);
       CountResults++;
      }
      if (LastPosition && LastPosition < ExpressionText.length) {
       document.getElementById('form_highlighttext').innerHTML += RemoveHTML(ExpressionText.substring(LastPosition, ExpressionText.length));
      }
     } else {
      // TODO
      document.getElementById('form_results').innerHTML += '' + ExpressionResults[0] + ' (' + ExpressionResults.index + ')' + '<br />';
      document.getElementById('form_results').innerHTML += '<br /><br />';
      //document.getElementById('form_highlighttext').innerHTML += ExpressionText.substring(StringPosition, ExpressionResults.index) + '<span class="highlight">' + ExpressionResults + '</span>';
     }
    } else {
     document.getElementById('form_error').innerHTML = 'No match found.';
    }
   } else {
    document.getElementById('form_error').innerHTML = 'You must enter both an expression and text to check that expression against.';
   }
   return false;
  } catch(e) {
   alert(e.message);
  }
 }
</script>
</head>

<body>
 <div id="form_help">
  <p>Regular expression notation:</p>
  <ul>
   <li>\b = Word boundary</li>
      <li>\B = Word nonboundary</li>
      <li>\d = Numeral (0-9)</li>
      <li>\D = Nonnumeral</li>
      <li>\s = Single whitespace</li>
      <li>\S = Single nonwhitespace</li>
      <li>\w = Letter, numeral, underscore</li>
      <li>\W = Not \w</li>
      <li>. = Any character except newline</li>
      <li>[] = Any character(s) in brackets</li>
      <li>[^] = Not []</li>
      <li>* = Preceding zero or more times</li>
      <li>? = Preceding zero or one time</li>
      <li>+ = Precending one or more times</li>
      <li>{<em>n</em>} = The preceding <em>n</em> times</li>
      <li>{<em>n</em>,} = <em>n</em> or more times </li>
      <li>{<em>n</em>,<em>m</em>}= At least <em>n</em>, at most <em>m</em>, times</li>
      <li>^ = Beginning of the string or line </li>
      <li>$ = End of the string or line </li>
  </ul>
 </div>
 <form onsubmit="return false;">
  <label for="InputExpression">Regular expression:</label><input type="text" id="InputExpression" value="" /><br />
  <label for="CheckCase">Ignore case:</label><input type="checkbox" id="CheckCase" /><br />
  <textarea cols="50" id="InputText" rows="5">Hello and welcome. I do hope you'll come again. Will you?</textarea><br />
  <input type="button" onclick="TestExpression();" value="Test expression" />
 </form>
 <div id="form_error" style="color:red;"></div>
 <div id="form_results"></div>
 <div id="form_highlighttext"></div>
</body>
</html>

As always, comments appreciated.

Tags:

Categories: tutorials/guides

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Making oXygen XML Editor (9.1) portable

The below information is correct for version 9.1. Comments on other versions are appreciated.

With flash drives becoming more and relevant, it's always good to find programs that can be run on these powerful drives. <oXygen/> XML Editor is one such program.

Making <oXygen/> portable

On the official site, there's a post regarding making <oXygen/> portable. However, what does it really involve?

Easily enough, it doesn't involve much more than is stated in the post.

First, you'll want to get a coyp of <oXygen/> installed onto your flash drive. I had previously installed <oXygen/> to my computer, so I just copied the Oxygen XML Editor 9 folder, within the Program Files directory, to my flash drive.

Next, there's a batch file called oxygen.bat in the main <oXygen/> directory.

If you open this in a text editor, like Notepad, you'll want to either comment out the below line, using rem at the beginning of the line, delete it, or modify it.

java  -Xss512k -Xmx256m -Dsun.java2d.noddraw=true -Dcom.oxygenxml.ApplicationDataFolder="%APPDATA%" -cp %CP% ro.sync.exml.Oxygen %1 %2 %3 %4 %5 %6 %7 %8 

The line you'll want to end up with is as follows.

java  -Duser.home=custom/license -Xss512k -Xmx256m -Dsun.java2d.noddraw=true -Dcom.oxygenxml.ApplicationDataFolder="%APPDATA%" -cp %CP% ro.sync.exml.Oxygen %1 %2 %3 %4 %5 %6 %7 %8 

The relevant text is -Duser.home=custom/license . In this case I've created a custom directory, under the <oXygen/> directory, as well as a license directory within that.

Once I run this batch file, it creates a lock file under this directory. In my case, G:\Oxygen XML Editor 9\custom\license\oxygen.lock

Once you've run the batch file, you can enter your license into <oXygen/> as usual. Once the copy has been registered, you can close out of <oXygen/> and/or the batch file. For any further <oXygen/> needs you can just open the main oxygen executable.

Portable apps

To see other applications that can be taken on the go, take a look at PortableApps.com.

Tags:

Categories: software, tutorials/guides

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Warhawk: Game Mode: Top 25,000(s) Analysis - 1/18/2008

I'm a statistics kind of guy. I like numbers, since they're logical. I also like trends, and all that.

So, here's a look at the current trends for what it takes to get into the top 25k, 50k, 75k, 100k, 150k, 200k, and 300k in the various game modes in Warhawk. Undoubtedly I'll have another post like this next month, around the same time.

With over 417,000 players, total, these equate to around the top 6%, 12.5%, 18.75%, 25%, 37.5%, 50%, and 75%.

Clearly, there are some modes that a number of individuals are not playing. This in turn means a smaller number of points need to be earned to enter the top players, world-wide.

Deathmatch

  • 25,000 = > 100
  • 50,000 = > 36
  • 75,000 = > 15
  • 100,000 = > 5
  • 150,000 = > 0
  • 200,000 = > 0
  • 300,000 = > 0

Team Deathmatch

  • 25,000 = > 975
  • 50,000 = > 494
  • 75,000 = > 305
  • 100,000 = > 199
  • 150,000 = > 90
  • 200,000 = > 39
  • 300,000 = > 2

Capture the Flag

  • 25,000 = > 6467
  • 50,000 = > 2502
  • 75,000 = > 1239
  • 100,000 = > 681
  • 150,000 = > 238
  • 200,000 = > 88
  • 300,000 = > 2

Zones

  • 25,000 = > 1483
  • 50,000 = > 720
  • 75,000 = > 416
  • 100,000 = > 259
  • 150,000 = > 106
  • 200,000 = > 42
  • 300,000 = > 0

Please note that numbers are subject to change. These numbers were correct as of approximately 9:45, CT.

Tags: ,

Categories: tutorials/guides