我正在编写一个正则表达式来检测一个字符串是否以有效的协议开头——现在可以说它可以是http或ftp—。协议后必须跟://, 和一个或多个字符,字符串中不能有空格,忽略大小写。
我有这个正则表达式可以做所有事情,除了检查字符串中的空格:
const regex = new RegExp('^(http|ftp)(://)((?=[^/])(?=.+))', 'i');
const urlHasProtocol = regex.test(string);
Run Code Online (Sandbox Code Playgroud)
^(http|ftp) — checks for http or ftp at the beginning
(://) — is followed by "://"
((?=[^/])(?=.+)) — is followed by a string that
(?=[^/]) — doesnt start with "/"
(?=.+) — has one or more characters
Run Code Online (Sandbox Code Playgroud)
那些必须通过:
http://example.com
http://example.com/path1/path2?hello=1&hello=2
http://a
http://abc
Run Code Online (Sandbox Code Playgroud)
那些必须失败:
http:/example.com
http://exampl e.com
http:// exampl e.com
http://example.com // Trailing space
http:// example.com
http:///www.example.com
Run Code Online (Sandbox Code Playgroud)
我正在尝试为空格添加规则。我正在尝试向前看,检查中间或末尾是否有一个或多个空格:(?=[^s+$])
^(http|ftp) — checks …Run Code Online (Sandbox Code Playgroud) 我有一个通过 Gitlab 部署的应用程序。为了将其部署到生产服务器,我使用了deploy_production. 基本上通过 ssh 进入,删除 node_modules 进行拉取、安装和构建:
image: node:latest\n\nbefore_script:\n - apt-get update -qq\n - apt-get install -qq git\n - \'which ssh-agent || ( apt-get install -qq openssh-client )\'\n - eval $(ssh-agent -s)\n - ssh-add <(echo "$K8S_SECRET_SSH_PRIVATE_KEY" | base64 -d)\n - mkdir -p ~/.ssh\n - \'[[ -f /.dockerenv ]] && echo -e "Host *\\n\\tStrictHostKeyChecking no\\n\\n" > ~/.ssh/config\'\n\nstages:\n - install\n - build\n - deploy_production\n\ncache:\n paths:\n - node_modules/\n\ninstall:\n stage: install\n script:\n - npm install\n artifacts:\n paths:\n - node_modules/\n\n\nbuild:\n stage: …Run Code Online (Sandbox Code Playgroud) 在 Ubuntu Server 20.04.2.0 上安装了全新的 Gitlab CE 13.9.1。这是管道
image: node:latest
before_script:
- apt-get update -qq
stages:
- install
install:
stage: install
script:
- npm install --verbose
Run Code Online (Sandbox Code Playgroud)
为了运行它,我使用与之前的 Gitlab CE 12 相同的过程配置我的 Gitlab Runner:
我拉取最后一个 Gitlab 运行程序图像:
docker pull gitlab/gitlab-runner:latest
Run Code Online (Sandbox Code Playgroud)
第一次尝试:
启动在本地卷上安装 GitLab Runner 容器
docker run -d \
--name gitlab-runner \
--restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
Run Code Online (Sandbox Code Playgroud)
并注册跑步者
docker run --rm -t -i \
-v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
Run Code Online (Sandbox Code Playgroud)
注册跑步者时,我选择执行者shell
最后,当我推送到 Gitlab 时,在管道上,我看到以下错误:
$ apt-get update …Run Code Online (Sandbox Code Playgroud) 我有一个对象。我知道我可以解构以检索任何条目的值,并使用扩展运算符来检索其余条目
\nconst [a, ...rest] = [1, 2, 3];\nconsole.log(a); // 1\nconsole.log(rest); // [ 2, 3 ]\nRun Code Online (Sandbox Code Playgroud)\n我想知道是否有任何sintaxis可以检索任何条目的值,并将对象本身重新声明为新的var,类似于以下\xe2\x80\x94,尽管我知道这是错误的\xe2\x80\x94:
\nconst [a], myArrayInANewVar = [1, 2, 3];\nconsole.log(a); // 1\nconsole.log(myArrayInANewVar); // [ 1, 2, 3 ]\n\nRun Code Online (Sandbox Code Playgroud)\n提前致谢!
\n