cannot figure what I am doing wrong. Regex nodes are identical… CH and ch should produce sane SUBn results but dont.
Dynamo 1.3.2 or 1.3.1
Figured it out - code is touchy… for the SUBN above:
##2018-04-19-Apsis0215@Gmail.com
import re ##Import for re or Regular Expressions
###INPUTS (Two Inputs- 0 and 1- ad inputs to python node to correspond with th [+] button)
StrList=IN[0] ##Simple list of items to match
regexPatt=IN[1] ##Regexp string to match
##see https://docs.python.org/3.3/howto/regex.html "Regular expressions in dynamo" and
##https://regex101.com for regular expressions 101 testing
RegExpSub=IN[2] ##Regexp substitution from IN[2]
##OUTPUT
Outlist = [] ##Outlist TRUE if match is find for each item in list
###Initialize Regexp
###The actual RegExp compare for each item in the list
for item in StrList: ## For each item in the list run a match
compile = re.compile( regexPatt, flags=re.IGNORECASE|re.MULTILINE)
result= re.subn (regexPatt, RegExpSub, item, count=0)[0]
Outlist.append (result)
##If match is not NONE then it is a match (true) - else (false)- append that to the list for each item
OUT=Outlist ##Set output to results
And I was quite happy and surprised this codeblock worked to pre/suffix lists:
##2018-04-19-Apsis0215@Gmail.com
import re ##Import for re or Regular Expressions
StrList=IN[0] ##Simple list of items to match
regexPatt=IN[1] ##Regex list of string patterns to return as match T/F
##see https://docs.python.org/3.3/howto/regex.html "Regular expressions in dynamo" and
##https://regex101.com for regular expressions 101 testing (Python)
Found=[] ##found T/F
###The actual RegExp compare for each item in the list
for item in StrList: ## For each item in the list run a match
xfound=False
for rs in regexPatt:
##Search for pattern
result= re.search (rs,item, flags=re.IGNORECASE|re.MULTILINE)
##If returns more than nothing it found something...
##Use ^ for start of string and $ for end for
#exact matches in pattern :: reMatch="^" + rexList + "$";
if result is not None:
xfound=True ##Pass to outer loop to record a FOUND 'TRUE' value
break
if xfound==False: ## If nothing was found then return false
Found.append(False)
else: ##Otherwise return true!
Found.append(True)
OUT=Found ##Set output to results
4 Likes