2
<html>
<head>
        <title>Test</title>
        <meta charset="UTF-8">

<script src="xregexp.js"></script>
<script src="unicode-base.js"></script>
<script src="unicode-scripts.js"></script>
<script>
var wordsToMatch = "Gr|Greek|ΕΛΛΗΝΙΚΑ";

var regexPattern = '\\b('+wordsToMatch+')';

var referenceRegex = new XRegExp(regexPattern, 'mi');
//var testString = "ΕΛΛΗΝΙΚΑ"; //null  -  ???
var testString = "Gr"; //Gr,Gr  -  OK AS IT SHOULD
var match = referenceRegex.exec(testString); 

function myFunction()
{
    alert(match);
}
</script>

</head>
<body onload="myFunction()">


</body>
</html>

I believe my example is quite explainable, it matches fine english words, I would like to match also Greek words too. I am not familiar with the unicode add-on of xregexp, my pattern was implemented to work with regexp.

  • I believe [this answer](http://stackoverflow.com/a/23327464/1256925) explains how to match all Greek characters. I assume you know where to go from there. – Joeytje50 May 22 '14 at 23:09

2 Answers2

0

You need the scripts addon besides the unicode base:

<script src="xregexp.js"></script>
<script src="addons/unicode/unicode-base.js"></script>
<script src="addons/unicode/unicode-scripts.js"></script>

<script>
  XRegExp("\\p{Greek}+").test("ΕΛΛΗΝΙΚΑ"); // true
</script>
gog
  • 10,367
  • 2
  • 24
  • 38
  • I added unicode-scripts.js but my example still doesn't work. I need the solution according to my pattern, as this is part of a far more complex pattern. – user3667005 May 22 '14 at 23:49
0
<html>
<head>
        <title>Test</title>
        <meta charset="UTF-8">
<script>
var wordsToMatch = "Gr|Greek|ΕΛΛΗΝΙΚΑ";

var regexPattern = '('+wordsToMatch+')';

var referenceRegex = new RegExp(regexPattern, 'mi');
//var testString = "ΕΛΛΗΝΙΚΑ"; //Works now fine
var testString = "Gr"; //Gr,Gr  -  OK AS IT SHOULD
var match = referenceRegex.exec(testString); 

function myFunction()
{
    alert(match);
}
</script>

</head>
<body onload="myFunction()">


</body>
</html>

The above works fine. A little bit reading in regular expressions and testing cleared my problem. Removed \b and also XRegExp isn't needed...