Question

I try to check if a string is part of a codepage like CP1254 or CP1250:

//cp1250
public static const CP1250_REGEXP:RegExp = /[\u00A0\u00A4\u00A6-\u00A9\u00AB-\u00AE\u00B0\u00B1\u00B4-\u00B8\u00BB\u00C1\u00C2\u00C4\u00C7\u00C9\u00CB\u00CD\u00CE\u00D3\u00D4\u00D6\u00D7\u00DA\u00DC\u00DD\u00DF\u00E1\u00E2\u00E4\u00E7\u00E9\u00EB\u00ED\u00EE\u00F3\u00F4\u00F6\u00F7\u00FA\u00FC\u00FD\u0102-\u0107\u010C-\u0111\u0118-\u011B\u0139\u013A\u013D\u013E\u0141-\u0144\u0147\u0148\u0150\u0151\u0154\u0155\u0158-\u015B\u015E-\u0165\u016E-\u0171\u0179-\u017E\u02C7\u02D8\u02D9\u02DB\u02DD\u2013\u2014\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2026\u2030\u2039\u203A\u20AC\u2122]/;

//cp1254
public static const CP1254_REGEXP:RegExp = /[\u00A0-\u00CF\u00D1-\u00DC\u00DF-\u00EF\u00F1-\u00FC\u00FF\u011E\u011F\u0130\u0131\u0152\u0153\u015E-\u0161\u0178\u0192\u02C6\u02DC\u2013\u2014\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2026\u2030\u2039\u203A\u20AC\u2122]/;
var stringValue = "Lorem ipsum"

if( CP1250_REGEXP.exec( stringValue ) ) {
trace( "is cp1250" );
}

if( CP1254_REGEXP.exec( stringValue ) ) {
trace( "is cp1254" );
}

But exec() only returns if one of the chars from stringValue has a char of the regexp pattern. And test() returns if the first char of the stringValue is equal.

In short: My aim is to check if all of the stringValue chars are equal to the pattern / part of the codePage.

But I am stucked at this point.

Was it helpful?

Solution

[\u00A0-\u00CF\u00D1-\u00DC\u00DF-\u00EF\u00F1-\u00FC\u00FF\u011E\u011F\u0130\u0131\u0152\u0153\u015E-\u0161\u0178\u0192\u02C6\u02DC\u2013\u2014\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2026\u2030\u2039\u203A\u20AC\u2122]

Matches any character in the set exactly once. Add a * to the expression to recognize any number of them (including 0, use + instead for 1 or more), and to consume the entire input, start with ^ (start of line) and end with $ (end of line), so like:

^[chars]*$

or, with your character set:

^[\u00A0-\u00CF\u00D1-\u00DC\u00DF-\u00EF\u00F1-\u00FC\u00FF\u011E\u011F\u0130\u0131\u0152\u0153\u015E-\u0161\u0178\u0192\u02C6\u02DC\u2013\u2014\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2026\u2030\u2039\u203A\u20AC\u2122]*$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top