Javascript: Turkish RegExp issue

I am working on a javascript search function. RegExp- this is '\\b('+word+')\\b', 'ig'for selecting and receiving a given word, but he simply selects English characters, does not select Turkish characters or anything else.

Job script: https://jsfiddle.net/kv4jftcz/2/

The script does not work: https://jsfiddle.net/kv4jftcz/3/

+4
source share
2 answers

You need to use RegExp with the tag u, but javascript will not support the unicode regex :( so to solve this problem you have to override \b. \baMeans [^\w]aso for Turkish characters;

[^\wığüşöçĞÜŞÖÇİ] - .

[^\wığüşöçĞÜŞÖÇİ](türkçe)[^\wığüşöçĞÜŞÖÇİ]

türkçe .

türkçe dili destekliyorum

^ $..

(?:^|[^\wığüşöçĞÜŞÖÇİ])(türkçe)(?:[^\wığüşöçĞÜŞÖÇİ]|$)

thats it..

. . . (^|[^\wığüşöçĞÜŞÖÇİ])(türkçe)([^\wığüşöçĞÜŞÖÇİ]|$) $1<span class="match">$2</span>$3.

: , , , javascript

	var word = 'İpsum';
	var rgx = new RegExp('(^|[^\wığüşöçĞÜŞÖÇİ])(' + word + ')([^\wığüşöçĞÜŞÖÇİ]|$)', 'ig');

	$('p, p *').contents().filter(function() {
	  return this.nodeType === 3;
	}).each(function() {
	  $(this).replaceWith($(this).text().replace(rgx, "$1<span class='match'>$2</span>$3"));
	});

	var positions = $('.match').map(function() {
	  return this.getBoundingClientRect().top;
	}).get();
div {
  font-size: 50px;
}
span.match {
  background: gold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>
  <p>Lorem İpsum dolor sit amet, consectetur adipisicing elit. Aut voluptatum, provident saepe. Culpa animi sint, itaque iure error hic qui blanditiis perspiciatis adipisci, libero quia veritatis dignissimos quasi id cumque!</p>
</body>
Hide result

. (, [hi] spe.cial characters). this

+3

Javascript Unicode , , ( ES6 ).

, ( \b, ), , , ASCII, . , RegexPal :

enter image description here

, XRegExp, Unicode.

UnicodeJS, , , , .

+1

All Articles