开发者

How can you print all the characters that satisfy a regular expression?

Is there a way of printing out every character that satifies a given regular expression?

For example, can I print all characters that matches regular expression, let's say, in Javascript:

[A-Za-z_-]|[\u00C0-\u00D6]|[\u00D8-\开发者_运维问答u00F6]|[\u00F8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|[\u10000-\uEFFFF]

Example taken from Turtle specification.

EDIT: JavaScript implementation of the solution proposed by Toby and Peter Boughton.

var out = "",
  str = "";
for (var i = 32; i < 983040; i++) {
  str = String.fromCharCode(i);
  if (str.match(/[A-Za-z_-]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|[\u10000-\uEFFFF]/)) {
    out += str;
  }
}
console.log(out);


I think the only way to do what you ask would be to loop through all possible characters one-by-one and "collect" each one that's a match into a buffer of some sort.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜