2012-05-19 2 views
-6

maya ascii 파일에는 다음과 같은 명령어가 포함되어 있습니다.정규 표현식 결과 파이썬이있는 concat 문자열

... 
createNode transform -n "pCylinder1"; 
createNode mesh -n "pCylinderShape1" -p "pCylinder1"; 
    setAttr ".vif" yes; 
    setAttr ".uvst[0].uvsn" -type "string" "map1"; 
createNode transform -n "pPlane1"; 
    setAttr ".t" -type "double3" 7.3666236108700112 0 -4.2288466031573595 ; 
createNode mesh -n "pPlaneShape1" -p "pPlane1"; 
    setAttr ".uvst[0].uvsn" -type "string" "map1"; 
    setAttr ".cuvs" -type "string" "map1"; 
createNode transform -n "pTorus1"; 
    setAttr ".t" -type "double3" -0.47688973199150198 0 -10.843417358550912 ; 
... 
connectAttr "polySphere1.out" "pSphereShape1.i"; 
connectAttr "polyCube1.out" "pCubeShape1.i"; 
connectAttr "polyCylinder1.out" "pCylinderShape1.i"; 
connectAttr "polyPlane1.out" "pPlaneShape1.i"; 
connectAttr "polyTorus1.out" "pTorusShape1.i"; 

... 

는이 라인에서, 나는 아래 라인의 모양을 라인을 검색해야합니다.

createNode transform -n nodeName -p "FG"; 
createNode transform -n nodeName -p "BG"; 
createNode transform -n nodeName -p "MG"; 

위의 항목을 찾기 위해 어떤 정규식을 사용해야합니까? 알려진 문자열

import re 

line = "createNode transform -n \"water\" -p \"FG\";" 

m = search(r'(FG|BG|MG)',line) 
if m: 
    result = m.groups()[0] 

    # What do you want to concat it to? 
    known_string = "known_string" + result 


내가 검색의 결과를 CONCAT 필요
(MG | | BG는 FG 수) : 여기

+5

질문에 조금 더 노력해야합니다. 바로 지금은 이해하기가 불가능합니다. – NPE

+0

확인. 나는 알려진 문자열을 가진 검색 결과 (FG | BG | MG 일 수 있음)를 연결해야합니다. 그것을 얻었으니 이제이 문자열을 검색해야합니다. 위의 예에서 line2가 알려져 있습니다. 잼은 알 수 없습니다. 라인은 FG, BG 또는 MG를 포함 할 수 있습니다. 선 = "createNode 변환 -n \"물 \ "-p \"FG \ "; – nish

+1

예제 입력과 해당 예상 출력을 보여줍니다. –

답변