x$
あなたのものは適切に文字列と一致しません。文字列全体に一致させたい場合は、試してください
"""^\$$|^[^\$].*$|^\$[^i\{].*$"""
ここで、 で区切られた 3 つのシーケンスのいずれかに一致します|
。
^\$$
^[^\$]+.*$
^\$[^i\{]+.*$
これを分解してみましょう:
// First pattern--match lone '$' character
^ // Matches start of string
\$ // Matches the literal character '$'
$ // Matches end of string
// Second pattern--match a string starting with a character other than '$'
^ // Start of string
[^\$]+ // Match at least one non-'$':
+ // Match one or more
[^ ] // ...of characters NOT listed...
\$ // ...namely, a literal '$'
.* // Any number of other characters
$ // End of the string
// Third pattern--match a string starting with '$' but not '$i' or '${'
^ // Start of string
\$ // The literal character '$'
[^i\{]+ // Match at least one non-'i'/non-'{'
.* // Any number of other characters
$ // End of the string
文字列全体に一致しない場合は、 などを心配する必要がありますfoo$image{Hi}
。空の文字列も一致させたい場合は^$|
、一致の先頭に追加します。
これは、パーサーコンビネーターを念頭に置いてではなく、特に正規表現で動作するように書かれていることに注意してください。他にどのようなルールがあるかによって、文字列全体を一致させたい場合と一致させたくない場合があります。