Regular expression not working for at least one European character

后端 未结 1 938
渐次进展
渐次进展 2020-11-27 08:08

I am checking whether my string contains at least one character of a European language(Example: German, Spanish,English etc...)

I tried like the following:



        
相关标签:
1条回答
  • 2020-11-27 08:48

    You just need to remove the anchors and the quantifier and use test:

    alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ß1111"))
    alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ö"))
    alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("12345"))

    The (?![×÷])[A-Za-zÀ-ÿ] regex is an adaptation of the regex provided in Useful ASCII Ranges. It will capture all Latin and accented characters.

    Some more language-related character ranges you can use:

    French Letters: [a-zA-ZàâäôéèëêïîçùûüÿæœÀÂÄÔÉÈËÊÏΟÇÙÛÜÆŒ]

    German Letters: [a-zA-ZäöüßÄÖÜ]

    Polish Letters only: [a-pr-uwy-zA-PR-UWY-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ] (Note that there is no Q, V and X in Polish, but if you want to allow all English letters as well, use [a-zA-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ])

    Italian Letters: [a-zA-ZàèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]

    Spanish Letters: [a-zA-ZáéíñóúüÁÉÍÑÓÚÜ]

    And some more...

    Swedish: [a-zA-ZäöåÄÖÅ] (link)

    Norwegian: [a-zA-ZæøåÆØÅ] (link)

    Danish (same as Norwegian): [a-zA-ZæøåÆØÅ] (link)

    Greek & Coptic + Greek Extended: [\u0370-\u03FF\u1F00-\u1FFF] (link)

    Russian: [а-яА-ЯёЁ] (link)

    Ukrainian: [а-щА-ЩЬьЮюЯяЇїІіЄєҐґ] (link)

    Serbian (Cyrillic): [А-ИК-ШЂЈ-ЋЏа-ик-шђј-ћџ] (link)

    Bulgarian (subset of Russian alphabet): [а-ъьюяА-ЪЬЮЯ] (link)

    Belarusian script range: [ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў] (link)

    Romanian: [a-zA-ZĂÂÎȘȚăâîșț] (link)

    0 讨论(0)
提交回复
热议问题