[英]How can I get this regex right?
我試圖用@
分割令牌,同時不允許特定字符。 我想出了這個
(@\w+[^ -+=(><)])
但它不能准確地工作! 假設我們的目標字符串是這樣的:
(() >= @a -5 and () <= @7 and ()= @127 and () = @1-7 and ()= @name_asd ()= @'hey this is a string')
它沒有得到單個字符的標記,而且它似乎接受了-
作為一個有效的字符,而它不應該! 我還希望能夠解析和匹配如下字符串:
@'something arbitrary with'
也一樣,但到目前為止無法弄清楚。
我需要用@
完全表示我想要的令牌
@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+|'[^']*')
同時將您的-
放在最后以避免形成不需要的范圍。 見演示:
https://regex101.com/r/sJ9gM7/87
它沒有獲得single character tokens
因為您在單個字符之后有一個空格,並且在\\w+
之后不允許有空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.