2014-05-23 2 views
0

나는 이와 같은 단어가 있습니다.javascript의 한마디 단어를 분리하십시오

런던 Hethrew 공항 (LHR)과 런던 Hethrew 공항 및 LHR로이 단어를 나눠야합니다.

이렇게 정규 표현식을 사용할 수 있습니까?

^[A-Za-z\w\s]{([a-z A-z]\)} 
+0

나는 생각하지 않는다 그래서 –

답변

2

왜 첫 번째 브래킷을 간단하게 나누지 않습니까?

var dataArray="London Hethrew Airport (LHR)".Split("("); 
dataArray[0]=dataArray[0].trim(); 
dataArray[1]=dataArray[1].replace(")","").trim(); 

니코

당신 같은 정규식으로 해당 문자열을 일치시킬 수 있습니다
2

:

^([^(]+)\s+\(([A-Z]+)\)$ 

설명 :

^      the beginning of the string 
    (      group and capture to \1: 
    [^(]+     any character except: '(' (1 or more 
          times (matching the most amount 
          possible)) 
)      end of \1 
    \s+      whitespace (\n, \r, \t, \f, and " ") (1 or 
          more times (matching the most amount 
          possible)) 
    \(      '(' 
    (      group and capture to \2: 
    [A-Z]+     any character of: 'A' to 'Z' (1 or more 
          times (matching the most amount 
          possible)) 
)      end of \2 
    \)      ')' 
    $      before an optional \n, and the end of the 
          string 
+3

또는 오히려 '^ (. +) \ s + \ (([AZ] +) \)' –

+0

큰 설명이지만 두 번째 캡처 그룹은 괄호와 일치하지 않으려 고합니다 – phuzi

+0

@phuzi 나를 위해 잘 작동하는 것 같습니다 : http://jsfiddle.net/Sw23W/ 나에게 잘못된 정보를 더 제공 할 수 있습니까? –

관련 문제