strict match anywhere in line regex python
Question: I need to strictly find line

`createNode transform -n "bar1_1" -p "bar1";` in a file that has many such
lines

    
    
    ...
    createNode transform -n "pTorus1";
        setAttr ".t" -type "double3" -0.47688973199150198 0 -10.843417358550912 ;
    createNode transform -n "bar1_1" -p "bar1";  < ----------- this one
        setAttr ".t" -type "double3" -20.4535357685646444 0 -10.843414345343878 ;
    createNode mesh -n "pTorusShape1" -p "pTorus1";
        setAttr -k off ".v";
        setAttr ".vir" yes;
        setAttr ".vif" yes;
        setAttr ".uvst[0].uvsn" -type "string" "map1";
        setAttr ".cuvs" -type "string" "map1";
        setAttr ".dcc" -type "string" "Ambient+Diffuse";
        setAttr ".covm[0]"  0 1 1;
        setAttr ".cdvm[0]"  0 1 1;
    createNode transform -n "bar1_1" -p "bar11"; < ------- not this
        setAttr ".t" -type "double3" -20.47342345353453535358 0 -10.843417342423342233 ;
    createNode lightLinker -s -n "lightLinker1";
        setAttr -s 2 ".lnk";
        setAttr -s 2 ".slnk";
    ...
    

tried this regex but it does not work,

    
    
    import re
    reg = re.compile("bar1")
    aa = "createNode transform -n "bar1_1" -p "bar11";"
    bb = reg.match(aa)
    

What regex should I use to strictly find line that contains -p "bar1" ( not
bar11, see marked line above ) ?


Answer: I'm not 100% clear on the question, but I think it's one of these two...:

    
    
    re.match(r'bar1.+', string) # make sure there's any remaining chars
    re.match(r'bar1\d+',string) # make sure there's digits after
    

Or, if your createNode wotsit is meant to be a string, you could mean:

    
    
    >>> s = 'aa = createNode transform -n "bar1_1" -p "bar11" and "bar1";'
    >>> re.findall(r'"(bar1.+?)"', s)
    ['bar1_1', 'bar11'] # note, that the added "bar1" is not returned
    

