ES regex does not recognise umlauts etc...

Advocate ,
Oct 04, 2016

Copy link to clipboard

Copied

Friends of regular expressions!

I want to check for valid (special) variable names and use

\w

for word characters. This does not find characters such as ä - or any other none-ASCI character.

My test script is this:

var toTest = [], j, n;
    toTest.push("#Apple");                            // true
    toTest.push("#Apfel, #apple, #Gurkensalateska");  // true
    toTest.push("#t_27Apples");                       // true
    toTest.push("#côté");                             // false
    toTest.push("#Grüne_5Äpfel");                     // false
    toTest.push("#Äpfel");                            // false

n = toTest.length;
for (j=0; j < n; j++) {
  $.writeln(ContainsVariable (toTest), " ", toTest);
}

function ContainsVariable (text) {
var re_variable= /(^#[\w][\d_\w]*)(, +)?/,
    indexOfChar, character, lSkip, kText;

  for(indexOfChar = 0; character = text[indexOfChar]; indexOfChar++) {
    kText = text.substring(indexOfChar); // rest of the statement
    sFound = kText.match(re_variable);
    if (sFound != null) {
      lSkip = sFound[0].length;
      indexOfChar = indexOfChar + lSkip -1;
      continue;
    }
    return false;
  }
  return true;
}

Any ideas how to get valid results for non-english variable names?

There seem to be other shortcomings also: indesign-scripting-forum-roundup-7#hd4sb​3.

I have not found any documation about the regex-flavour of ES. Isn't there any?

Klaus

TOPICS
Scripting

Views

167

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Advocate , Oct 04, 2016
K.Daube Advocate , Oct 04, 2016
Well, friends, this page gave me a hint:var re_variable= /(^#[A-Za-z\u00C0-\u017E][\d_A-Za-z\u00C0-\u017E]*)(, +)?/,works as intended.Thanks for listeningKlaus

Likes

Translate

Translate
Jump to answer Jump to answer
Advocate ,
Oct 04, 2016

Copy link to clipboard

Copied

Well, friends, this page gave me a hint:

var re_variable= /(^#[A-Za-z\u00C0-\u017E][\d_A-Za-z\u00C0-\u017E]*)(, +)?/,

works as intended.

Thanks for listening

Klaus

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more