I have an install.js script inside a xpi package that have this js: var re = /(.*?)\.(\d+)$/; re.test("184.108.40.2062111900"); The script dies with the following: Error: can't convert Error to string Error: re.test is not a function Source File: Line: 10 isn't it possible to use regexp inside a js script in a xpi package?
while this works... weird! myProductRegVersion = "220.127.116.112111900" var re = new String(myProductRegVersion); re.search(/(.*?)\.(\d+)$/);
> var re = /(.*?)\.(\d+)$/; var re = "/(.*?)\.(\d+)$/"; will probably get you more mileage. And I agree with the error message. re.test is not a function.
Henrik, are you trying to compare the used mozilla version? You can do that with this example: const NEED_MOZ_BUILD = 2002101708; if (buildID < NEED_MOZ_BUILD) foo else bar
comment 2: brush up on regular expressions. no quotes around regexp literals and RegExp objects most definitely have a test function.
-var re = /(.*?)\.(\d+)$/; +var re = /(.*)\.(\d+)$/; the '?' has nothing to act on.
Thanks Henrik, you saved my day :) The workaround is in fact: new RegExp("(.*?)\\.(\\d+)$") This one will has a test() method and everything. Somehow a regexp literal isn't a real regexp in install.js, just as a string literal isn't a real string. Creating them explicitely with the "new" operator works however.
Can anyone confirm that this bug is either bogus (as I suspect, in agreement with comment #5) or fixed?
not a bug
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.