From Wildcards To Regular Expressions

There are a lot of people out there that no how to do file searches and Microsoft Word searches by using wildcard characters, but not as many people know how to work with regular expressions. That is the main reason why I added the RegExp.fromWildExp() function to jPaq. In addition, I have created an example page which dynamically generates the regular expression from the wildcard expression that you specify. Check this jPaq example out by clicking here.  The initial example shows you how to write a regular expression that matches all text that starts at the beginning of a word with a capital “J” and ends at the end of a word with a lowercase “t”.  NOTE:  Unlike regular expressions, wildcard expressions look to find the smallest match possible.

getMatches(str, exp)

I recently encountered two troubling bugs with jPaq’s String.prototype.indexOfPattern() function.  In order to fix it, I ended up exploring the powerful String.prototype.replace() function, exploiting the parameter passed into the callback function.  I already knew that the matched text and sub-groups were passed into the callback function.  The thing that I didn’t know was that the second-to-the-last parameter passed is the start index of the matched string.  This gave me the idea to create a function which can return an array of all of the matches and sub-groups in object literals, along with the offset and original text.  Instead of me explaining it, take a look:

function getMatches(str, exp) {
  var ret = [];
  str.replace(exp, function() {
    var match = {length : arguments.length - 2};
    for(var i = 0, iOffset = match.length; i < iOffset; i++)
      match[i] = arguments[i];
    match.offset = arguments[i];
    match.original = arguments[i + 1];
  return ret;

No jPaq.openWindow() For Now

Up until today, I was interested in writing a more object oriented version of the native function.  Unfortunately, I found out that there are some major incompatibility issues between browsers.  Let’s take this example for instance:"", "", "left=100,screenX=100,top=100,screenY=100,height=400");"", "", "left=100,screenX=100,top=100,screenY=100,width=400");

As you may have already guessed, the above code is simply supposed to open two new windows whose top, left corner is 100 pixels from both the top and left edge of the screen. The first window should have a height of 400 pixels and arbitrary width and the second should have a width of 400 pixels and arbitrary height. Ordinarily this code would work as expected, but on Google Chrome 10.0.648.204 and Mac OSX 10.6.5 the the windows end up being 22 pixels from the left and top of the screen. In addition, neither window has constrained the size of the window as I specified. After doing a little more testing to see if I could modify the values after creating the window, I realized that it may not be worth it to waste my time on this right now.

If you think you have found a solution to my problem, please let me know.