我會去對於以下正則表達式與re.search
s= 'Latitude E6430 (Latitude E6430)'
m = re.search('([a-zA-Z]+) ([a-zA-Z]*\d+[a-zA-Z]*)', s)
然後
m.group(1) # Latitude
m.group(2) # E6430
正則表達式的解釋是
NODE EXPLANATION
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[a-zA-Z]+ any character of: 'a' to 'z', 'A' to 'Z'
(1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
' '
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
[a-zA-Z]* any character of: 'a' to 'z', 'A' to 'Z'
(0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
[a-zA-Z]* any character of: 'a' to 'z', 'A' to 'Z'
(0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \2
任何嘗試嗎? – Rahul
爲什麼要使用正則表達式? –
**模型將始終包含數字**在給定示例中自相矛盾(E6430,8460p) – ZdaR