concat字符串与正则表达式python的结果

时间:2012-05-19 07:14:24

标签: python regex

maya ascii文件包含以下指令行。

...
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";

我应该使用什么正则表达式来查找上述任何内容。

1 个答案:

答案 0 :(得分:1)

以下是您对描述的最佳表现:

我需要使用已知字符串连接搜索结果(可能是FG | BG | 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

“现在我需要搜索这个字符串。为什么?你已经搜索了它 “zam未知 - 不,不是,这是re.compile()

的结果

抱歉,我无法进一步说明您的说明