我试图用@分割令牌,同时不允许特定字符。 我想出了这个
(@\w+[^ -+=(><)])但它不能正常工作! 假设我们的目标字符串是这样的:
(() >= @a -5 and () <= @7 and ()= @127 and () = @1-7 and ()= @name_asd ()= @'hey this is a string')它不会获得单个字符标记!?,它似乎也接受-作为一个有效的字符,而它不应该! 我还希望能够解析和匹配字符串,如:
@'sth arbitrary with'同样,但到目前为止无法弄明白! 我很高兴知道如何解决这个问题。
更新 : 我需要使用@ altogether获取令牌,这意味着我想要的
@a For () >= @a -5 @7 For () <= @7 @127 For ()= @127 @1 For () = @1-7 @name_asd For ()= @name_asd and @'hey this is a string' For ()= @'hey this is a string'I am trying to split tokens with @, and well meanwhile not allowing specific characters. I came up with this
(@\w+[^ -+=(><)])But it doesn't work precisely!. suppose our target string is this :
(() >= @a -5 and () <= @7 and ()= @127 and () = @1-7 and ()= @name_asd ()= @'hey this is a string')it doesn't get single character tokens!?, and also it seems to accept - as a valid character while it shouldn't! I also wanted to be able to parse and match strings like :
@'sth arbitrary with'as well, but couldn't figure it out so far! I would be grateful to know how to fix this.
Update: I need to get the token with @ altogether meaning I want
@a For () >= @a -5 @7 For () <= @7 @127 For ()= @127 @1 For () = @1-7 @name_asd For ()= @name_asd and @'hey this is a string' For ()= @'hey this is a string'最满意答案
@(?:\w+|'[^']*')请参阅demo.Also place ur -最后避免形成不需要的范围。参见演示。
https://regex101.com/r/sJ9gM7/87
它没有获得single character tokens因为你在单个字符之后有一个空格而你在\w+之后没有允许空格。
@(?:\w+|'[^']*')See demo.Also place ur - at the end to avoid forming an unwanted range.See demo.
https://regex101.com/r/sJ9gM7/87
It wasnt getting single character tokens coz you have a space after single character and you have not allowed a space after \w+.
更多推荐
发布评论