English 中文(简体)
MySQL REGEXP:匹配空白条目
原标题:MySQL REGEXP: matching blank entries
  • 时间:2010-06-17 23:40:59
  •  标签:
  • mysql
  • regex

我有这样的条件,即应收回所有满足特定reg状态的浏览器:

country REGEXP ( ^(USA|Italy|France)$ )

然而,我需要增加一种模式,以收回所有空白的国家价值。 目前,我正在使用这一条件。

country REGEXP ( ^(USA|Italy|France)$ ) OR country = ""

如果不列入《儿童权利公约》条款,如何发挥同样的作用?

Thanks, Erwin

问题回答

这一工作应当:

country REGEXP ( ^(USA|Italy|France|)$ )

然而,从业绩角度看,你可能希望利用IN syntax。

country IN ( USA , Italy , France ,   )

由于区域评价方案可能相当缓慢,以后应该更快。

您没有理由使用(>$)(在座标的末尾)来填写您的“低压”问题。

它看上去了一个微薄的圆形,但country REGEXP (^USA, Italy, Kluwer( )/code>将工作。

你可以尝试:

country REGEXP ( ^(USA|Italy|France|)$ )

我在France后添加了另一个 >/code>,该编码应基本上将其贴在>>>>^$上,该编码与country = 相同。

<>Update:,因为这一方法没有工作,我建议你使用这一规定:

country REGEXP ( ^(USA|Italy|France)$|^$ )

请注意,您可以使用:^(USA Kluwer, Kluwer,{0})$,因为它会抱怨说,有空话。 虽然>>(USA Kluwer) ,|.{0}$将有效。

这里有一些例子说明这一规定的收益价值:

select    regexp  ^(USA|Italy|France)$|^$ 
> 1
select  abc  regexp  ^(USA|Italy|France)$|^$ 
> 0
select  France  regexp  ^(USA|Italy|France)$|^$ 
> 1
select     regexp  ^(USA|Italy|France)$|^$ 
> 0

你可以看到,这完全是你想要的。

如果你想要将空白值(如0个空间和5个空位都算作空白)对待,那么你就应当使用reg:

country REGEXP ( ^(USA|Italy|France|s*)$ )

这将使上个例子中的最后一行不同,即:

select     regexp  ^(USA|Italy|France|s*)$ 
> 1




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...