c-smile / sciter-sdk

Sciter is an embeddable HTML/CSS/scripting engine
http://sciter.com
Other
2.11k stars 224 forks source link

Regexp bug #169

Closed SonnyX closed 4 years ago

SonnyX commented 4 years ago
(new RegExp(/\.(\w{3,4})$/, "gm")).exec("https://somedomain.com/somelink.png")[1];

does not give back png for some reason, instead gives an undefined. It should be noted that I'm doing something slightly silly here: namely using a regexp inside a regexp.

This works in firefox. Tested with sciter v4.3.0.19 and sciter v4.4.3.21

c-smile commented 4 years ago

Yes, it is a bug now in RegExp(otherRegExp) constructor.

Use either one of these:

const re = /\.(\w{3,4})$/;
var ext1 = "https://somedomain.com/somelink.png".match(re)[1];
var ext2 = re.exec("https://somedomain.com/somelink.png")[1];
SonnyX commented 4 years ago

Since the support for new Regexp(re) constructor has been removed, closing this issue

c-smile commented 4 years ago

I do not quite sure I understand the purpose of such ctor in JS.

Why do you need this:

(new RegExp(/\.(\w{3,4})$/, "gm")).exec("https://somedomain.com/somelink.png")[1];

when you can simply do this

(/\.(\w{3,4})$/gm).exec("https://somedomain.com/somelink.png")[1];

Yet

var ext = "https://somedomain.com/somelink.png" %~ ".";

See "String Operators" in https://sciter.com/docs/content/script/language/Expressions.htm

SonnyX commented 4 years ago

I agree that there is no use for such a constructor in Javascript. I only saw in your release notes that the constructor is now removed a release, therefor this issue is solved. Solved issues should not remain open, and therefor I closed it.