1
我从sp_helpconstraint iyas_grandtest获取此信息。在Sybase ASE中发现主键/唯一键:正则表达式和PHP
constraint_name definition
iyas_grand_2317208971 PRIMARY KEY INDEX (id) : CLUSTERED
iyas_grand_2317208972 UNIQUE INDEX (unik) : NONCLUSTERED
iyas_grand_2317208973 UNIQUE INDEX (comp_unik1, comp_unik2) : NONCLUSTERED
我想提取:从小学
- ID,从独特的
- 的Unik,
- comp_unik1和comp_unik2从独特的
如下:
- $键[] = ID
- $独特[ 'iyas_grand_2317208972'] [] =场Unik
- $独特[ 'iyas_grand_2317208973'] [] = comp_unik1
- $独特[ 'iyas_grand_2317208973'] [] = comp_unik1
请注意,有时PRIMARY键可能是PRIMARY KEY INDEX(id,id2)。我现在有一个缺陷(只检测1个组合键的键,如果有_则截断名称,即'comp_unik1'变成'comp')。
$sql = sybase_query("sp_helpconstraint iyas_grandtest");
while($row = sybase_fetch_assoc($sql)) {
$txt= $row['definition'];
$re1='(PRIMARY)'; # Word 1
$re2='.*?'; # Non-greedy match on filler
$re3='(?:[a-z][a-z]+)'; # Uninteresting: word
$re4='.*?'; # Non-greedy match on filler
$re5='(?:[a-z][a-z]+)'; # Uninteresting: word
$re6='.*?'; # Non-greedy match on filler
$re7='((?:[a-z][a-z]+))'; # Word 2
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches))
{
$word =$matches[2][0];
$keys = explode(",", $word);
}
}
谢谢!你的答案和这个^ \ w + \ s +(?: PRIMARY KEY | UNIQUE)INDEX \((。*?)\)有什么区别(结果) – Iyas 2011-12-28 08:30:17
是的。首先,你不会逃离外面的包袱,这意味着你不会有比赛。如果你确实逃避了它们,那么你的正则表达式不会表现得很好,因为你使用了一个懒惰的量词,这意味着正则表达式引擎将不得不寻找_each_字符来查找关闭元素,而提供的正则表达式不必去做。 – fge 2011-12-28 09:59:01
再次感谢。你能建议任何书籍/教程/网站/以帮助提高正则表达式技能? – Iyas 2011-12-29 00:32:17