简体   繁体   English

正则表达式匹配-以某个字符结尾...但有一个转折

[英]Regex matching — Ending with a certain character…but with a twist

Ok so I am having trouble solving a problem with having a Regex using JAVASCRIPT with a small time application I am making. 好的,所以我在使用JAVASCRIPT和正编写的少量应用程序解决Regex问题时遇到了麻烦。

To create a variable in my application a user input is received in the following format: 要在我的应用程序中创建变量,将以以下格式接收用户输入:
begin with { 首先 {
end with } 以}结尾
have var(varName,YES OR NOT IN HERE)= ANYTHING 有var(varName,YES OR NOT HERE)在任何地方

Example: 例:

{var(myVar,YES)=tryHard} {var(myVar,YES)= tryHard}

or 要么

{var(someOther,NO)=552*232} {var(someOther,NO)= 552 * 232}

Here is the regex I am currently using to verify this format: 这是我目前用来验证此格式的正则表达式:

/{var\([\d\w]{1,10},(YES|NO)\)=.*}$/

Problem is verifying the following text: 问题是验证以下文本:

someGarbageHere{var(myVar,YES)=2*5}moreGarbagehere

Any ideas? 有任何想法吗? I was thinking there would be some sort of flag but that did not pan out. 我当时在想会有某种标志,但是没有成功。 Also I am thinking that maybe starting the string with . 我也在想,也许以开头。 << any character might be a solution but I really just want the text enclosed in the curly braces. <<任何字符都可以解决,但我真的只想将花括号括起来的文字。

Do you want that text to be accepted or not? 您是否要接受该文本? If yes, take out the $ at the end of the regex. 如果是,请在正则表达式末尾取出$。 If no, put a ^ at the beginning of the regex ($ matches end-of-string, ^ matches beginning-of-string). 如果否,则在正则表达式的开头放置一个^($匹配字符串的结尾,^匹配字符串的开头)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM