내가 (이 링크에서 : get python dictionary from string containing key value pairs) 아래 정규식이 :정규식 찾기 단어 "-"
내 문자열이 있음을 가지고\b # Start at a word boundary
(\w+) # Match and capture a single word (1+ alnum characters)
\s*:\s* # Match a colon, optionally surrounded by whitespace
([^:]*) # Match any number of non-colon characters
(?= # Make sure that we stop when the following can be matched:
\s+\w+\s*: # the next dictionary key
| # or
$ # the end of the string
) # End of lookahead
내 질문은 여기에
r"\b(\w+)\s*:\s*([^:]*)(?=\s+\w+\s*:|$)"
는 설명이다 단어 사이에 "-", 예를 들어 : movie-night
, 위의 정규 표현식이 작동하지 않습니다 그리고 나는 그것이 b(\w+)
것으로 생각합니다. 이 정규식을 "-"을 포함한 단어로 변경하려면 어떻게해야합니까? 나는 b(\w+-)
을 시도했지만 작동하지 않습니다. 사전에 도움을 주셔서 감사합니다.
'b ([\ -] +)'시도해보십시오. – shantanoo
예제에서 콜론은 어디에 있습니까? 정규식에 하나의 정규식이 필요한 것 같습니다. –