• 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
  • EvanShultz
    EvanShultz over 8 years ago
    Thanks for the help!

    I ended up doing this:
    ; sanitize input field for use as a regex, going character-by-character through the input
    searchString = ""
    foreach(char parseString(QSC_fnData->filter "")
    ; char is either a wildcard which is converted for the regex, a regex special char that is escapted, or passed through
    cond(
    ((char == "*") searchString = strcat(searchString ".*"))
    (stringp(index("^.$|()[]+?" char)) searchString = strcat(searchString "\\" char))
    (t searchString = strcat(searchString char))
    )
    )

    ; put start and end anchors on search string built above
    ; generate assoc list of all nets then regex pattern match for search string, resulting in a list of matching net names
    NetList = mapcar('cadr rexMatchAssocList(strcat("^" searchString "$") mapcar(lambda((item) list(item->name item)) axlDBGetDesign()->nets)))
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • EvanShultz
    EvanShultz over 8 years ago
    Thanks for the help!

    I ended up doing this:
    ; sanitize input field for use as a regex, going character-by-character through the input
    searchString = ""
    foreach(char parseString(QSC_fnData->filter "")
    ; char is either a wildcard which is converted for the regex, a regex special char that is escapted, or passed through
    cond(
    ((char == "*") searchString = strcat(searchString ".*"))
    (stringp(index("^.$|()[]+?" char)) searchString = strcat(searchString "\\" char))
    (t searchString = strcat(searchString char))
    )
    )

    ; put start and end anchors on search string built above
    ; generate assoc list of all nets then regex pattern match for search string, resulting in a list of matching net names
    NetList = mapcar('cadr rexMatchAssocList(strcat("^" searchString "$") mapcar(lambda((item) list(item->name item)) axlDBGetDesign()->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