我正在编写正则表达式以从下面的句子中提取令牌,例如“(”是LEFT_BRACKET,“是”是IS,“teddy”是属性(TEDDY,INT),“或”是“OR”,“ NULL“为NULL,”)“是RIGHT_BRACKET。但不知何故,最后一个单词NULL将作为属性(NULL)而不是单独的标记NULL。如果我在NULL之后给出空格,那么只有它作为标记,否则它与属性匹配。请帮助解决此问题。
**Sentence is** (data is teddy or is NULL)
**The corresponding regex is as follows:**
<b>1. regex to resolve ")"</b>
case class LEFT_BRACKET() extends Token {
override def pattern: Parser[Token] = regex("\\(".r) ^^ (_ => LEFT_BRACKET)
}
<b>2. regex to resolve "is"</b>
case class IS() extends Token {
override def pattern: Parser[Token] = regex("(?i)^is ".r) ^^ (_ => IS)
}
<b>3. regex to resolve "teddy"</b>
def attrR = regex("[\\{\\{]*[a-zA-Z_][a-zA-Z0-9_.}}]*[\\}\\}]*".r)
def attribute: Parser[ATTRIBUTE] = (attrR) ^^ (attr => {
val dTYPE: TYPE = TYPE.STRING
ATTRIBUTE(attr, dTYPE)
})
<b>4. regex to resolve "or"</b>
case class OR() extends Token {
override def pattern: Parser[Token] = regex("(?i)^is ".r) ^^ (_ => OR)
}
<b>5. regex to resolve "null"</b>
case class NULL() extends Token {
override def pattern: Parser[Token] = regex("(?i)^null ".r) ^^ (_ => NULL)
}
**Above case classes are being called with the help of object.**