A regular expression that allows you to use all the characters of the alphabet plus Unicode characters

I need a regular expression to allow all characters of the alphabet plus the Greek / German alphabet in a string, but instead of these characters ?,&,^," . *

I skipped the character list to run away to make the question simple. I really want to see how to do this and then include alphabet sets using ASCII codes.

+4
source share
3 answers

If you have a finite and short set of elements to replace, you can just use a class, for example.

  string.replace(/[?\^&]/g, '*'); 

and add as many characters as you want to reject. you can also add the Unicode character ranges you want to replace (e.g. \u017F-\036F\u0400-\uFFFF )

otherwise, use class a to indicate which characters do not need to be replaced, such as az, accented / diacritic letters, and Greek characters

  string.replace(/[^az\00C0-\017E\u0370-\03FF]/gi, '*'); 
+4
source

You should use the XRegexp plugin as well as the Unicode add-on .

Once you do this, you can use modern regular expressions such as /[\p{L}\p{Nl}]/ , which necessarily also include those \p{Greek} code points that are letters or letters. But you can also select /[\p{Latin}\p{Greek}]/ if you wish.

Javascripts own regular expressions are terrible. Use XRegexp .

+4
source

So something like: /^[^?&\^"]*$/ (This means that the string consists only of characters outside of the five you have listed) ...

But if you want to have Greek characters and Unicode characters (what are Unicode characters ??)? You may need to use http://xregexp.com/ This is a javascript regex library that includes character classes for various Unicode character classes (I know I'm repeating) plus other โ€œcommandsโ€ to handle Unicode.

+1
source

Source: https://habr.com/ru/post/1401636/


All Articles