[問題] 字串內含「*」時的比對問題

看板Perl作者 (忍蛋)時間17年前 (2008/05/15 14:43), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
  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)

05/15 16:14, , 1F
]if ($string1 =~ /\Q$string2\E/)
05/15 16:14, 1F

05/15 19:50, , 2F
感謝指點 在文件中翻到\Q \E的用法了
05/15 19:50, 2F

05/16 01:04, , 3F
if (index($string1, $string2) >= 0) 亦可
05/16 01:04, 3F
文章代碼(AID): #18AzkVVm (Perl)
文章代碼(AID): #18AzkVVm (Perl)