Hi,
 
I am trying to use variable in regular expressions but its not working for some reason.
 
I am using Jython that comes with WebSphere 6.1.
 
wsadmin>print oNodes
ndm-ws16a(cells/WS16/nodes/ndm-ws16a|node.xml#Node_1)
wsejbfpp1wpdiu528(cells/WS16/nodes/wsejbfpp1wpdiu528|node.xml#Node_1)
wsadmin>
 
wsadmin>print oNodeList
['ndm-ws16a(cells/WS16/nodes/ndm-ws16a|node.xml#Node_1)', 'wsejbfpp1wpdiu528(cells/WS16/nodes/wsejbfpp1wpdiu528|node.xml#Node_1)']
wsadmin>
 
wsadmin>print nodeName
wpdiu528
wsadmin>
 
wsadmin>expr = r".*wpdiu528.*"
wsadmin>pat4 = re.compile(expr)
wsadmin>m = re.search(expr,oNodes)
wsadmin>print m
org.python.modules.sre.MatchObject@7b507b50
wsadmin>
wsadmin>m.group()
'wsejbfpp1wpdiu528(cells/WS16/nodes/wsejbfpp1wpdiu528|node.xml#Node_1)'
 
This 'wsejbfpp1wpdiu528(cells/WS16/nodes/wsejbfpp1wpdiu528|node.xml#Node_1)' is the desired result. I am able to achieve this result when I provide "wpdiu528" directly in variable expr. But I would like to use another variable called nodeName in place of the string "wpdiu528" inside the regular expression.
 
I tried as shown below, but it fails.

wsadmin>expr = r".*%nodeName.*"
wsadmin>pat4 = re.compile(expr)
wsadmin>m = re.search(expr,oNodes)
wsadmin>print m
None
wsadmin>
wsadmin>m.group()
WASX7015E: Exception running command: "m.group()"; exception information:
 com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<input>", line 1, in ?
AttributeError: 'None' object has no attribute 'group'
wsadmin>
 
Please see if you can assist me here...