• 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. Help for Regular Expression, thanks in advance!

Stats

  • Replies 2
  • Subscribers 160
  • Views 13159
  • Members are here 0
More Content

Help for Regular Expression, thanks in advance!

Jason Hsu
Jason Hsu over 5 years ago

Hi,

  Could anyone please tell me how to change the line to a list? Now, I have one ptf file. It contains all of information, PACK_TYPE, TYPE, PART_TYPE, OTHER, MERGE_ADDCOMP, ALT_SYMBOLS, HEIGHT, JEDEC_TYPE. They were divided by a pipe(|). Every time, I will read one line. And I want to make it as a list. I attempt to use RE, but I failed. Please help me to change it, thanks a lot.

For example, the line is the follow.

'F_X4'|'RA_PF'|'TYCO_2214762-5'|'ELASTO-GASKET_LITE-PIPES' ('!')='29-7810-01'|''|'(PFCON-80-ZSFP2X2-LP1X4-T22_IMPERIALXL,PFCON-80-ZSFP2X2-LP4X2-T22_PASSPORTXL)'|'1016'|'CON-80-SFP2PF-LP-T64':CDS_LW_PART_NUMBER='29-7810-01'

I want to make it as:

("F_X4" "RA_PF" "TYCO_2214762-5" "ELASTO-GASKET_LITE-PIPES ('!')='29-7810-01" "(PFCON-80-ZSFP2X2-LP1X4-T22_IMPERIALXL,PFCON-80-ZSFP2X2-LP4X2-T22_PASSPORTXL)" "1016" "CON-80-SFP2PF-LP-T64:CDS_LW_PART_NUMBER='29-7810-01'"

Please help me, Thanks in advance.

Regards

Jason

  • Sign in to reply
  • Cancel
  • B Bruekers
    B Bruekers over 5 years ago

    First of all, why do you want to use regular expression for this? The matching is limited to 9 captured parts. Your example contains 8 parts, so that should be ok. 

    A parseString() also does the job.

    If you want to assign the fields to a variable then you better use  destructuringBind(). 

    some examples:

    str= "'F_X4'|'RA_PF'|'TYCO_2214762-5'|'ELASTO-GASKET_LITE-PIPES' ('!')='29-7810-01'|''|'(PFCON-80-ZSFP2X2-LP1X4-T22_IMPERIALXL,PFCON-80-ZSFP2X2-LP4X2-T22_PASSPORTXL)'|'1016'|'CON-80-SFP2PF-LP-T64':CDS_LW_PART_NUMBER='29-7810-01'"

    line = parseString(str "|")
    pp(line)

    pcre = pcreCompile("(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)")
    when(pcreMatchp(pcre str)
     f1 = pcreSubstitute(pcre "\\1")
     f2 = pcreSubstitute(pcre "\\2")
     f3 = pcreSubstitute(pcre "\\3")
     f4 = pcreSubstitute(pcre "\\4")
     f5 = pcreSubstitute(pcre "\\5")
     f6 = pcreSubstitute(pcre "\\6")
     f7 = pcreSubstitute(pcre "\\7")
     f8 = pcreSubstitute(pcre "\\8")
     line = list(f1 f2 f3 f4 f5 f6 f7 f8)
     pp(line)
    )

    destructuringBind( (f1 f2 f3 f4 f5 f6 f7 f8 @rest junk) parseString(str "|")
     line = list(f1 f2 f3 f4 f5 f6 f7 f8)
     pp(line)
    )

    Bram

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Jason Hsu
    Jason Hsu over 5 years ago in reply to B Bruekers

    Thank you, Bram, My thought is immature. Now, I know how to do it after read your code. Thank you very much for your help. Thanks:)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
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