Home > Community > Forums > Custom IC SKILL > Is it possible to specify a variable with rexMatchp?

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Is it possible to specify a variable with rexMatchp? 

Last post Fri, May 17 2013 1:52 AM by Andrew Beckett. 6 replies.
Started by adeuser777 14 May 2013 03:25 PM. Topic has 6 replies and 779 views
Page 1 of 1 (7 items)
Sort Posts:
  • Tue, May 14 2013 3:25 PM

    Is it possible to specify a variable with rexMatchp? Reply

    Hi,

    Can we have a variable with rexMatchp?

    My requirement is as below:

    a = "m_1"

    b = '("m_1" "m_1_1" "m_1_2")

    c = setof(i  b  !rexMatchp("_[1-9]*$" i)   // This will return nil.

    My desired output for c is "m_1" and at the same time, I want to exclude a_[1-9] where a="m_1"

    Could you please guide? Is it possible with rexMatchp?

     

    Thanks,

    Ram 

     

    • Post Points: 20
  • Tue, May 14 2013 4:06 PM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,576
    • Points 15,725
    Re: Is it possible to specify a variable with rexMatchp? Reply

    Hi Ram,

    I'm confused as to what you want, your requirements are mutually exclusive - you want to match "m_1" but you don't want to match a (which is "m_1") - can you clarify your requirement please?

    Probably the trick will be to either build the rexMatchp test expression using sprintf() where the variable can be inserted into the test expression [e.g. sprintf(nil "%s*$" a) ], and/or make a more complex condition which can be written as a single compound/composite expression [e.g. "this" || ("that" && "theOther") - this OR (that AND theOther) ].

    Anyway, I hope this helps you.

    Regards,

    Lawrence.

    • Post Points: 20
  • Wed, May 15 2013 1:40 AM

    Re: Is it possible to specify a variable with rexMatchp? Reply

    I assume you want:

    rexCompile(strcat(a "_[1-9]*$"))
    c=setof(i b !rexExecute(i))

    This will return ("m_1")

    Andrew.

    • Post Points: 20
  • Wed, May 15 2013 10:35 AM

    Re: Is it possible to specify a variable with rexMatchp? Reply

    Sorry for not being clear. Let me explain what I am trying to do.

    "a" could fall under one of the following category.

    a = '(m1 m1_1 m1_2...)    or a = '(mn_1 mn_1_1 mn_1_2...)

    My end goal is to get the "original name (orig_name) with out _[1-9]. And if the original name itself had _[0-9] in it, I need to handle it appropriately.

     

    I have implemented the following to handle this scenario.

    rexCompile("_[0-9]$")

    if(rexExecute(orig_name) then mainInst = car(setof(i insts !rexMatchp("@" i) && !rexMatchp("_[0-9]_[1-9][0-9]*$" i)))

    else parentInst = car(setof(i insts !rexMatchp("@" i) && !rexMatchp("_[1-9][0-9]*$" i)))

     

    Is there a better way to handle this? Thanks. 

    • Post Points: 20
  • Thu, May 16 2013 1:59 AM

    Re: Is it possible to specify a variable with rexMatchp? Reply

    Your requirements are still as clear as mud, I'm afraid. I've really no idea what you are trying to achieve. Originally a was a string - now it is a list. Your example doesn't even mention a so I don't know what you are trying to do.

    Best thing is to describe a number of different sets of input and output data - with some detailed description of what you want it to do.

    Are you using IC61? If so, the pcre functions allow a lot more power in the regular expressions than the old rex functions.

    Regards,

    Andrew.

    • Post Points: 20
  • Thu, May 16 2013 10:15 AM

    Re: Is it possible to specify a variable with rexMatchp? Reply
    Hi Andrew,
    My apologies. I have corrected the description.

    "b" could fall under one of the following category.

    Case 1:
    b = '("/i0/i1/m1" "i0/i1/m1_1" "i0/i1/m1_2"...)
    a = "m1"

    Expected output = "i0/i1/m1"

    Case 2:
    b = '("/i0/i1/mn_1" "/i0/i1/mn_1_1" "/i0/i1/mn_1_2"...)
    a = "mn_1"

    Expected output = "i0/i1/mn_1"

    My end goal is to get the original name "a" with out _[1-9]. And if the original name itself had _[0-9] in it, I need to make sure, it's handled appropriately.

    I have implemented the following to handle this scenario.

    rexCompile("_[0-9]$")

    if(rexExecute(a) then mainInst = car(setof(i b !rexMatchp("_[0-9]_[1-9][0-9]*$" i))

    else mainInst = car(setof(i b !rexMatchp("_[1-9][0-9]*$" i))

    The above lines are doing the job. Could you please let me know if there is a better way?

    Thanks.
    • Post Points: 20
  • Fri, May 17 2013 1:52 AM

    Re: Is it possible to specify a variable with rexMatchp? Reply

    Isn't this just  rexMatchList(strcat(a "$") b) ? Or the car of that if you want the first match?

    Regards,

    Andrew.

    • Post Points: 5
Page 1 of 1 (7 items)
Sort Posts:
Started by adeuser777 at 14 May 2013 03:25 PM. Topic has 6 replies.