-3

sshで接続するターミナルからの特定のタイプのプロンプトを処理するドライバーを作成しています。

The code in the driver is looking for a particular pattern received from the device to know when to send additional commands or exit, etc.

The code in the driver takes the pattern as a regular expression. I've tried numerous different combinations of patterns for the regex to handle this prompt '(Cisco Controller) >', but to no avail. I've tried to escape the parenthesis '\(Cisco Controller\)\s*>', I've tried with raw string r'\(Cisco Controller\)\s*>', and I've tried multiple other combinations, but I usually end up with the error "Unbalanced Parenthesis" or "Bogus escape character". Why can't I get the regex engine to accept this pattern?

4

1 に答える 1

1

あなたが投稿した文字列の未加工のバージョンに問題はありません...文字列でテストすると、'(Cisco Controller) > Command to execute would be here'うまく一致するようです。

Python 2.6.8 (unknown, Jun  9 2012, 11:30:32)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> regex = re.compile(r'\(Cisco Controller\)\s*>')
>>> match = regex.search('(Cisco Controller) > Command to execute would be here')
>>> match
<_sre.SRE_Match object at 0x7ff3e720>
>>>
于 2012-07-18T12:58:47.830 に答える