简体   繁体   English

如何将模式另存为environment.prod.ts中的ENV变量?

[英]How to save pattern as ENV variable in environment.prod.ts?

I save a pattern in an ENV variable in environment.prod.ts eg: 我将模式保存在environment.prod.ts中的ENV变量中,例如:

export const environment = { production: true, regExpTs : /^(?=.*[az])(?=.*[AZ])(?=.*\\d)(?=.*[#$@!%&*?])[A-Za-z\\d#$@!%&*?]{8,30}$/i, regExpHTML : '^(?=.*[az])(?=.*[AZ])(?=.*\\d)(?=.*[#$@!%&*?])[A-Za-z\\d#$@!%&*?]{8,30}$', };

The background of this idea is to be able to change the pattern when needed dynamically from the env and also to hide it from being embedded directly the HTML. 这个想法的背景是能够在需要时从env动态更改模式,并将其隐藏起来而不直接嵌入HTML。

The first variable: regExpTs is being used in the *.ts file and it's working fine. 第一个变量: regExpTs正在*.ts文件中使用,并且工作正常。 The issue I face is regarding the variable: regExpHTML . 我面临的问题是有关变量: regExpHTML

I read the varaible in the *.ts file as: let PASS_REGEXP_HTML = environment.regExpHTML; 我将*.ts文件中的变量读取为: let PASS_REGEXP_HTML = environment.regExpHTML; and then I pass it as interpolation in the *.component.html within the specific input field. 然后将其作为内插值传递到特定输入字段的*.component.html中。

Eg <input type="password" patter="{{PASS_REGEXP_HTML}}" ../> The interpolation is also working fine, but the problem is that the pattern is somehow being changed and is't not the one saved in ENV any more. 例如, <input type="password" patter="{{PASS_REGEXP_HTML}}" ../>插值也可以正常工作,但是问题在于模式正在以某种方式更改,而不是保存在ENV中的模式更多。

It changes from: 它从:

^(?=.*[az])(?=.*[AZ])(?=.*\\d)(?=.*[#$@!%&*?])[A-Za-z\\d#$@!%&*?]{8,30}$

to: 至:

^(?=.*[az])(?=.*[AZ])(?=.*d)(?=.*[#$@!%&*?])[A-Za-zd#$@!%&*?]{8,30}$

First what's the reason that it's being changed and the second what would be the solution and/or the fix for such issue? 首先是要更改它的原因是什么,其次是该问题的解决方案和/或解决方法是什么?

It is because of backslash. 这是因为反斜杠。 Change your regExpHTML to following 将您的regExpHTML更改为

^(?=.*[az])(?=.*[AZ])(?=.*\\\\d)(?=.*[#$@!%&*?])[A-Za-z\\\\d#$@!%&*?]{8,30}$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular environment.ts 问题 JSON。 但是 environment.prod.ts - Angular environment.ts problem JSON. However environment.prod.ts 如何将 Terraform output 变量保存到 Github Action 的环境变量中 - How to save Terraform output variable into a Github Action’s environment variable Prod Env 中的格式错误的 Json 异常 - Malformed Json Exception in Prod Env 如何使用 kubectl 在部署中修补容器环境变量? - How to patch container env variable in deployment with kubectl? 从Postman函数中的json输出保存环境变量 - Save environment variable from json output in postman function 如何在 Github Actions 中添加传递 env 变量作为 json 的一部分? - How to add pass a env variable as part of a json in Github Actions? 我们如何将 JSON 凭证存储到 python 中的 ENV 变量? - How can we store a JSON credential to ENV variable in python? 当我从 .env 获取 API_URL 作为环境变量时,出现错误。 我安装了 dotenv - when I fetch API_URL from .env as an environment variable, I get an error. I have dotenv installed 如何使用Angular将.json配置导入到environment.ts并使用api? - How to import .json config to environment.ts and consume api using Angular? 如何将配置 json 加载为环境变量 nodejs - How to load config json as environment variable nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM