如何使用quotemeta在Perl中查找和更改字符串

时间:2014-06-17 07:22:19

标签: regex string perl

我的字符串= <bibliomixed>Williams, G. L. (2004) The Higher Education Market in the United Kingdom. In P. Teixeira, B. Jongbloed, D. Dill and A. Amaral, <emphasis role="italic">Markets in Higher Education: Rhetoric or Reality?</emphasis> Dordrecht, the Netherlands: Kluwer.</bibliomixed>

我想在HTML文档中找到此字符串并进行更改。但我在HTML文档中搜索上面的字符串时使用了quotemeta函数,它在来自quotemeta函数后给出了以下字符串:

\<bibliomixed\>Williams\,\ G\.\ L\.\ \(2004\)\ The\ Higher\ Education\ Market\ in\ the\ United\ Kingdom\.\ In\ P\.\ Teixeira\,\ B\.\ Jongbloed\,\ D\.\ Dill\ and\ A\.\ Amaral\,\ \<emphasis\ role\=\"italic\"\>Markets\ in\ Higher\ Education\:\ Rhetoric\ or\ Reality\?\<\/emphasis\>\ Dordrecht\,\ the\ Netherlands\:\ Kluwer\.\<\/bibliomixed\>

所以当用这个字符串搜索时没有在perl中找到并且还试图用带有正则表达式选项的notepad ++查找字符串,那也没有用

请任何人建议任何解决方案

提前致谢

1 个答案:

答案 0 :(得分:0)

#!/usr/bin/perl
use strict;
use warnings;
my $string = q|<bibliomixed>Williams, G. L. (2004) The Higher Education Market in the United Kingdom. In P. Teixeira, B. Jongbloed, D. Dill and A. Amaral, <emphasis role="italic">Markets in Higher Education: Rhetoric or Reality?</emphasis> Dordrecht, the Netherlands: Kluwer.</bibliomixed>|;
my $html = q|<html><head><body>something.....nowmy string <bibliomixed>Williams, G. L. (2004) The Higher Education Market in the United Kingdom. In P. Teixeira, B. Jongbloed, D. Dill and A. Amaral, <emphasis role="italic">Markets in Higher Education: Rhetoric or Reality?</emphasis> Dordrecht, the Netherlands: Kluwer.</bibliomixed> now some extra text|;
my $result = index $html, $string;
print "$result";

如果结果不是-1,则表示匹配。