• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. Accepting user input with wildcards (regex help)

Stats

  • Replies 3
  • Subscribers 159
  • Views 14627
  • Members are here 0
More Content

Accepting user input with wildcards (regex help)

EvanShultz
EvanShultz over 9 years ago

I want to accept user input that contains wildcards for ref des and net names. The basic solution isn't difficult and I get good results with:

; build regular expression pattern of filter text
; put start and end anchors on text and all asterisks match "any character zero or more times"
rexCompile(buildString(parseString(strcat("^" "input_string" "$") "*") ".*"))

(I know I can use the PCRE functions, but I started with the basic ones since they worked.)

Trouble came when I tried to find pathological cases and realized that regex special chars are common in net names (especially "+" like in "+5V"). Some regex special chars are ".\*+^$".

Starting with the first problem I encountered, I was able to modify the following code to handle a plus sign:

pat = pcreCompile("[\\+]")
rexCompile(buildString(parseString(strcat("^" pcreReplace(pat "input_string" "\\\\+" 0) "$") "*") ".*"))

This does work and I can then accept an asterisk as a wildcard on the input and match "+5V", "+3.3V", etc. in my net names. But this is just one of the special chars. As the special chars could be in any position of the input string (ref des or net name), I don't see any one regex pattern to handle it all and doing them individually looks miserable. There must be a better way which I don't see. Searching on the forums and reading sklangref again haven't lit a bulb over my head, but it may be because I'm just daft.

Moving through the string character-by-character and replacing special chars with escaped versions would be an option, but that's rather painful and sure to incur a delay that users would notice on a big design (I tried using axlDBCloak while comparing the input string to the regex and didn't see a speed up, possibly because I'm only doing a database read?). The "Find by Name or Property" form does the same thing but query results appear instantly. It even handles multiple wildcards properly, so there's a way to do it well but I haven't figured it out. Can anyone help?

  • Sign in to reply
  • Cancel
Parents
  • B Bruekers
    B Bruekers over 9 years ago

    2 things, 

    i would do a parse string on the search string, convert it and then replace the regex characters with something else. Place them in a new list and build the list again. The resulting string is then the search string. 

    l_str = parseString("+sdrsf*" "")
    new_str = nil
    while(l_str
    str=car(l_str)
    l_str=cdr(l_str)
      case(str
      ("+" push(".+" new_str))
      ("*" push(".*" new_str))
      (t push(str new_str))
    )
    )
    new_str= buildString(new_str "")
    pp(new_str)

    2nd, if you first make an assoc list of the nets (netname net dbID) then you can use the pcreMatchAssocList to do a complete match of the lists of nets. This runs fast on my PC. 

    l_assocNet= mapcar( lambda((item) list(item->name item)) axlDBGetDesign()->nets)
    pcre= pcreCompile(".*3V.*" 1)
    l_nets= pcreMatchAssocList(pcre l_assocNet)

    The '1' in the pcreComplie is to ignore case sensitive.

    The l_nets contains an assoc list, like:

    ("+3V3" dbid:394326552)
    ("3V3_FB" dbid:394326384)
    ("3V3_COMP" dbid:394326272)

    To keep only the dbid's you can do a mapcar:

    l_nets= mapcar('cadr l_nets)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • B Bruekers
    B Bruekers over 9 years ago

    2 things, 

    i would do a parse string on the search string, convert it and then replace the regex characters with something else. Place them in a new list and build the list again. The resulting string is then the search string. 

    l_str = parseString("+sdrsf*" "")
    new_str = nil
    while(l_str
    str=car(l_str)
    l_str=cdr(l_str)
      case(str
      ("+" push(".+" new_str))
      ("*" push(".*" new_str))
      (t push(str new_str))
    )
    )
    new_str= buildString(new_str "")
    pp(new_str)

    2nd, if you first make an assoc list of the nets (netname net dbID) then you can use the pcreMatchAssocList to do a complete match of the lists of nets. This runs fast on my PC. 

    l_assocNet= mapcar( lambda((item) list(item->name item)) axlDBGetDesign()->nets)
    pcre= pcreCompile(".*3V.*" 1)
    l_nets= pcreMatchAssocList(pcre l_assocNet)

    The '1' in the pcreComplie is to ignore case sensitive.

    The l_nets contains an assoc list, like:

    ("+3V3" dbid:394326552)
    ("3V3_FB" dbid:394326384)
    ("3V3_COMP" dbid:394326272)

    To keep only the dbid's you can do a mapcar:

    l_nets= mapcar('cadr l_nets)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information