Jump to content

if condition with wildcards in strings in python?


Recommended Posts

just a simple question:

 

I want to scan object styles.

for example "BA-I-BST-370-230-BFT" contains the letters *BST*

 

in a worksheet I would write sth like =if('stylename'='*BST'; yes;no)

 

in Python I tried (running in a foreach-procedure, it has to filter all slab styles, which names contain the letters BST): (i read somewhere that '.+' is the Asterisk equal for python)

if outValue == ('.+BST.+'):

 

however, it doesn't filter work, why?

Edited by matteoluigi
Link to comment
39 minutes ago, matteoluigi said:

in Python I tried (running in a foreach-procedure, it has to filter all slab styles, which names contain the letters BST): (i read somewhere that '.+' is the Asterisk equal for python)

if outValue == ('.+BST.+'):

 

however, it doesn't filter work, why?

 

If you want to use regular expressions, you have to use explicitly the module "re", the one handling regular expressions: https://docs.python.org/3.8/library/re.html

Be careful that in regular expressions .+ means "at least one character", which might not what you seem to want.

Edited by Nicolas Goutte
  • Like 1
Link to comment
14 hours ago, Nicolas Goutte said:

If you want to use regular expressions, you have to use explicitly the module "re"

that's to complicated, I solved it with a substring

(of course the letters 'ABB', 'BST' or 'NEU' always appear at the third place in the stylename which has to be separated by '-' 😉)

 

Quote

ok, outValue, outType, outMap  = vs.IFC_GetPsetProp2((HNDL),'IfcBeam','Name')
Style = vs.SubString(outValue, '-', 3)

if Style == 'BST':

     .......

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...