我的情况适合使用 ' 吗? /我'正则表达式属性?

发布于 2024-10-12 11:58:49 字数 651 浏览 3 评论 0原文

我正在制作一个包含我的特定版本的 VMWare 支持的所有可能操作系统名称的大型目录。最初我是按照 VMX 文件中的方式编写它们的,但后来我发现了一个网站,其中列出了所有这些内容,问题是它们的大小写不正确,无法提供“完美”匹配,这是否是使用不区分大小写的正则表达式属性?

另外一个问题是,是否可以从网站中提取操作系统列表?它们看起来位于 HTML 格式的图表中。这会节省我很多时间,不必把它们全部打出来。

我查看了 HTML::Table extract,但我不太明白如何使用它。就表格而言,我能够在网站代码中找到该部分,并将其复制到一个新的 html 文件中,这样我就可以将其放在桌面上。

这很奇怪,我可能错过了一些东西。但我无法匹配不区分大小写。当用 /xmi 结束我的正则表达式时,我得到这个输出;

在 discovery4.pl 第 146 行的串联 (.) 或字符串中使用未初始化的值 $guest_os

我发现这意味着没有匹配项与我尝试打印的标量关联。

无论如何,我知道我有一个问题,它不想与任何情况匹配,因为如果我将 winnetstandard 修改为 winNetStandard 它会起作用并说:; Windows Server 2003 标准版。这是它应该说的。

I am making a large catalogue of all of the possible OS names that can be supported by my particular version of VMWare. Originally I was writing them all as they stood in the VMX files but then I found a website that had them all listed, the problem is they are not properly cased to provide a "perfect" match, would this be the perfect time to use the regex attribute for case insensitivity?

Also as a side question, would it be possibly extract the list of OSs from the website?. They look to be in a HTML formated chart. It would save me a lot of time having to type them all out.

I looked at HTML::Table extract, and I don't really understand how to use it. As far the table is concerned I was able to find the section in the websites code and I copied to a new html file so I can have it on my desktop.

This is odd, I am probably missing something. But I am not able to match with case insensitivity. When end my regex with /xmi I get this output;

Use of uninitialized value $guest_os in concatenation (.) or string at discovery4.pl line 146.

Which I have discovered mean that there is no match to associate to the scalar I am trying to print.

Anyhow I know I am having a problem with it not wanting to match with no case because if I modify winnetstandard to winNetStandard it works and says,;
Windows Server 2003, Standard Edition. Which is what it should say.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-10-19 11:58:49

HTML::TableExtract 可能会有所帮助。就匹配而言,我不确定您要匹配什么;如果您只是比较两个名称,uc($foo) eq uc($bar) 更有意义。但是,如果您有一个正则表达式,并且希望整个匹配不区分大小写,那么 /i 就可以做到。

啊,所以您想获取支持的操作系统名称并将它们组装成正则表达式并使用它进行匹配?然后,给定 @osnames,您可能需要这样的内容:

my $osnames = join('|', map quotemeta, sort { length($b) <=> length($a) } @osnames);
my $regex = qr/guestOS\s*=\s*"(?i:$osnames)"/;

?i: 将不区分大小写的范围限制为仅操作系统名称;仅当您希望 guestOS 也不区分大小写时,您才会使用 /i (和 (?:$osnames))。

HTML::TableExtract can be helpful. As far as matching goes, I'm not sure what it is that you are trying to match; if you are just comparing two names, uc($foo) eq uc($bar) makes more sense. But if you have a regex and want the whole match to be case insensitive, /i will do that.

Ah, so you want to get the supported os names and assemble them into a regex and match using it? Then, given @osnames, you might want something like this:

my $osnames = join('|', map quotemeta, sort { length($b) <=> length($a) } @osnames);
my $regex = qr/guestOS\s*=\s*"(?i:$osnames)"/;

The ?i: limits the scope of case insensitivity to just the OS names; only if you want guestOS to also be case insensitive would you use /i (and (?:$osnames)).

拥抱影子 2024-10-19 11:58:49

这是使用 /i 属性的正确时机,因为更改大小写并不会真正造成任何损害。要获取操作系统列表,我要做的就是复制列表所在部分的 html,在列表上使用正则表达式,以便它以您需要的格式输出,然后使用输出的文本。

This would be the right time to use the /i attribute, as changing the case can't really harm anything. What I would do to get the list of Operating Systems would be to copy the html of the sections where the list is, use regex on the list so that it outputs in the format you need it to, and then use the outputted text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文