Regular Expression in SKILL

Guest
Suppose a legal string is (REG-|CAP-)*TRA, i.e. zero or more occurrences of "REG" and "CAP" followed by "TRA". Example: REG-REG-CAP-REG-TRA is a valid sequence.

How do we code the above regular expression in SKILL?

The * operator seems to work only over a single character rather than a string.
 
If zero or more occurrences of "REG" and "CAP"
I would match for "TRA" only.
Does this make sense?

rexCompile("[TRA]")
=> t
rexExecute( "REG-REG-CAP-REG-TRA" )
=> t

Bernd
 
On 07/26/12 14:24, Bernd Fischer wrote:
If zero or more occurrences of "REG" and "CAP"
I would match for "TRA" only.
Does this make sense?

rexCompile("[TRA]")
=> t
rexExecute( "REG-REG-CAP-REG-TRA" )
=> t

Bernd
If using IC61X, you could use the pcre functions which are much more
powerful than the old rex functions (these use the Perl Compatible
Regular Expression library). So:

pat=pcreCompile("^(REG-|CAP-)*TRA$")

and then:

pcreExecute(pat "REG-TRA")
t
pcreExecute(pat "RFG-TRA")
nil
pcreExecute(pat "REG-REG-CAP-REG-TRA")
t
pcreExecute(pat "REG-RFG-CAP-REG-TRA")
nil

Note, as Bernd says, there's not much point even checking for the REG-
and CAP- bits if you are allowing zero or more matches, and it's not
anchored. In my example above I anchor the expression with ^ and $ to
ensure it's a complete string. Or I could have used + instead of *, but
even then it's still not that useful - depends to some extent what
you're trying to do with the result. I guess you could use this
unanchored pattern:

pat=pcreCompile("(REG-|CAP-)*TRA")
pcreExecute(pat "REG-RFG-CAP-REG-TRA") => t
pcreSubstitute(pat "\\0") => "CAP-REG-TRA"

in order to find the bit that matched.

Regards,

Andrew.
 

Welcome to EDABoard.com

Sponsor

Back
Top