从字符串中删除引号 [英] Removing quotes from string

查看:83
本文介绍了从字符串中删除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我认为这只是一个简单的问题,但是我得到了不正确的结果.基本上我试图删除字符串周围的引号.例如,我有字符串01:00",我想要 01:00,下面是我认为如何做到这一点的代码:

So I thought this would just be a simple issue however I'm getting the incorrect results. Basically I am trying to remove the quotes around a string. For example I have the string "01:00" and I want 01:00, below is the code on how I thought I would be able to do this:

$expected_start_time = $conditions =~ m/(\"[^\"])/;

每次运行它都会返回 1,所以我猜它只是返回 true 而不是真正从引号中提取字符串.无论引号02:00"、02:20"、08:00"等中是什么,都会发生这种情况.

Every time this runs it returns 1, so I'm guessing that it is just returning true and not actually extracting the string from the quotes. This happen no matter what is in the quotes "02:00", "02:20", "08:00", etc.

推荐答案

您所忘记的只是 LHS 将匹配项放入列表上下文以便返回子匹配组的括号.通常的做法是:

All you forgot was parens for the LHS to put the match into list context so it returns the submatch group(s). The normal way to do this is:

 ($expected_start_time) = $condition =~ /"([^"]*)"/;

这篇关于从字符串中删除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆