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?
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.
In reply to skillUser:
I assume you want:
rexCompile(strcat(a "_[1-9]*$"))c=setof(i b !rexExecute(i))
This will return ("m_1")
In reply to Andrew Beckett:
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.
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.
In reply to adeuser777:
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.
Isn't this just rexMatchList(strcat(a "$") b) ? Or the car of that if you want the first match?