作者Baternest (忍蛋)
看板Perl
標題[問題] 字串內含「*」時的比對問題
時間Thu May 15 14:43:37 2008
example:
$string1 = "hello*world";
$string2 = "hello*world";
if ($string1 =~ /$string2/) 不成立
但是string1拿掉中間的「*」號,反而OK
請問要如何解決呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.229.171.217
※ 編輯: Baternest 來自: 61.229.171.217 (05/15 14:55)
1F:推 LiloHuang:]if ($string1 =~ /\Q$string2\E/) 05/15 16:14
2F:→ Baternest:感謝指點 在文件中翻到\Q \E的用法了 05/15 19:50
3F:推 audreytang:if (index($string1, $string2) >= 0) 亦可 05/16 01:04