最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regular Expression to match English and Non English characters - Stack Overflow

programmeradmin1浏览0评论

I am trying to match a sentence that contains both English and Non English characters but does not contain pure numeric including decimals.

Example - Should match::

Renforcé-Bettwäschegar BLUMIRA123

Not match::

999.99

The following code matches everything that's not contained in the ASCII characters -

[^\u0000-\u0080]+

This is all I have at the moment. Any help will be much appreciated.

Thank you.

I am trying to match a sentence that contains both English and Non English characters but does not contain pure numeric including decimals.

Example - Should match::

Renforcé-Bettwäschegar BLUMIRA123

Not match::

999.99

The following code matches everything that's not contained in the ASCII characters -

[^\u0000-\u0080]+

This is all I have at the moment. Any help will be much appreciated.

Thank you.

Share Improve this question asked Dec 19, 2013 at 14:03 thinking_hydrogenthinking_hydrogen 1891 gold badge5 silver badges15 bronze badges 2
  • So it should match strings which contain at least one English letter ([a-zA-Z]) and one accented/diacritic letter ([àáâäåÀÁÂÃçÇêéëèÊËÉÈïíîìÍÌÎÏñÑöòõóÓÔÕÖÒšŠúüûùÙÚÜÛÿŸýÝžŽ])? Is there a need for non-ASCII characters? – mtanti Commented Dec 19, 2013 at 14:29
  • mtanti - Thanks for your ment. There's no need for non-ASCII characters. Thank you. – thinking_hydrogen Commented Dec 19, 2013 at 14:39
Add a ment  | 

4 Answers 4

Reset to default 2

See if this works:

.*([a-zA-Z].*[àáâäåÀÁÂÃçÇêéëèÊËÉÈïíîìÍÌÎÏñÑöòõóÓÔÕÖÒšŠúüûùÙÚÜÛÿŸýÝžŽ]|[àáâäåÀÁÂÃçÇêéëèÊËÉÈïíîìÍÌÎÏñÑöòõóÓÔÕÖÒšŠúüûùÙÚÜÛÿŸýÝžŽ].*[a-zA-Z]).*

First of all I'll assume that you have split your text into sentences. Then try this:

!/(?:^| )[0-9]+(?:\.[0-9]+)?(?: |$)$/.test(sentence);

For example, this is the returned result for each of the below sentences:

Renforcé-Bettwäschegar BLUMIRA123 //true
999.99                            //false
Another test                      //true
Hi this is a test 124             //false
Hi this is a test 124.23          //false

This should do the trick

!/^[0-9.]+$/.test(s)

Please note that will match only numbers and decimals, so you need to negate it (the !)

Thanks for the inputs. The below regex seem to work for me.

^([x00-\xFF]+[a-zA-Z][x00-\xFF]+)*
发布评论

评论列表(0)

  1. 暂无评论