登录
首页 >  Golang >  Go问答

golang正则关于<?=的替代

来源:SegmentFault

时间:2023-02-24 14:10:08 426浏览 收藏

怎么入门Golang编程?需要学习哪些知识点?这是新手们刚接触编程时常见的问题;下面golang学习网就来给大家整理分享一些知识点,希望能够给初学者一些帮助。本篇文章就来介绍《golang正则关于=的替代》,涉及到go、正则表达式,有需要的可以收藏一下

问题内容

golang正则报错

 "注册日期",
        "user_id" => "客户编号",
        "username" => "客户姓名",
        "gender" => "性别",
        "phone" => "联系电话",
        "openid"=>"openid",
        "content" => "影像文件下载链接",
        "share_time" => "分享链接日期",
    ];
    protected $filter_header = ["created_at", "share_time"];
    protected $table_option = [
        "gender" => [
            'type' => self::TYPE_SELECT,
            'data' => [1 => "先生", 2 => "女士"],
        ],
        "created_at" => [
            'type' => self::TYPE_TIME,
        ],
        "share_time" => [
            'type' => self::TYPE_TIME,
        ],
    ];
    protected $table_ext_button = [];
    protected $search_header = ["phone", "username"];

    protected function data(Query $model, $page, $search, $filter = false, $w = [])
    {
        if (empty($_REQUEST["filter"]) && empty($_REQUEST["search"])) {
            $model->where(["id" => "999999999"]);
        }
        $admin_info = AdminModel::getInstance()->where(["id" => Session::get("user")["user_id"]])->find();
        $w["business_id"] = $admin_info["business_id"];
        $data = parent::data($model, $page, $search, $filter, $w); // TODO: Change the autogenerated stub
        for ($i = 0; $i where(["id" => $id])->find();
        $admin_info = AdminModel::getInstance()->where(["business_id" => $user_info["business_id"]])->find();
        $array = [1 => "先生", 2 => "女士"];
        if ($admin_info["type"] == 0) {
            $sms_name = SignModel::getInstance()->where(["id" => $admin_info["sms_id"]])->find()["ems_sign"];
            $msg = "【{$sms_name}】尊敬的:{$user_info["username"]}{$array[$user_info["gender"]]}!您的影像文件可以下载了,请您务必于7天内扫描二维码或通过公众号登录下载,并妥善保存,谢谢!";
            try {
                SystemModel::sendCode($user_info["phone"], $msg);
                SmsModel::getInstance()->add(["title" => "影像下载通知", "business_id" => Session::get("user")["business_id"], "user_name" => $admin_info["name"], "phone" => $user_info["phone"], "content" => $msg, "username" => $admin_info["username"], "name" => $user_info["username"], "business_sms_name" => $admin_info["business_sms_name"]]);
                UserModel::getInstance()->where(["id" => $id])->save(["content" => $content, "share_time" => date("Y-m-d H:i:s")]);
            } catch (Exception $exception) {
                $this->displayByError($exception->getMessage());
            }
            $this->displayBySuccess();
        }
        if ($user_info["is_bind"] == 1) {
            $this->displayByError("用户已解绑,无法推送");
        }
        if(empty($user_info["openid"])){
            $this->displayByError("用户openid为空");
        }
        UserModel::getInstance()->where(["id" => $id])->save(["content" => $content, "share_time" => date("Y-m-d H:i:s")]);
        $push_log = WechatOfficialAccountModel::sendMessage($user_info["openid"], $user_info["business_id"], "template_one",
            "https://{$_SERVER['HTTP_HOST']}/Api/Login/download.html?id={$user_info["business_id"]}", "尊敬的{$user_info["username"]}{$array[$user_info["gender"]]},您的影像文件已经可以下载了,请您务必于7天内,点击本条信息“查看详情”登录下载,并妥善保存。", [$user_info["phone"], date("Y-m-d H:i:s")], "下载影像时,请先将整个文件夹保存到您的网盘,再登录您的网盘将文件下载到您的手机或电脑。可能有些文件在您的网盘里不能直接预览缩略图,这属于正常现象,请您先将文件下载到您的手机或电脑里,再从手机或电脑里打开文件就可以了,感谢您的配合");
        LogerModel::addLog("push_log", json_encode($push_log));
        $this->displayBySuccess();
    }

    public function search()
    {
        $this->displayByData([], "UserExt/search");
    }
}

相关代码

r, e := regexp.Compile("(?

异常

错误信息 error parsing regexp: invalid or unsupported Perl syntax: `(?

正确答案

golang正则不支持环视语法,但你可以用捕获组的方式去处理

\bclass\s(\w+)

然后获取捕获组group1就是class的值了

测试文本发这里

以上就是《golang正则关于=的替代》的详细内容,更多关于golang的资料请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>