SKILL Regular Expression Numbered Register

J

Jake

Guest
Hi,

I'm writing a SKILL script, and I'm using regular expressions to parse
a file. In the documentation, it states that you can match a piece of
a regular expression and that the value is then stored in a numbered
register. However, I can't seem to figure out from the documentation
what name is given to this register or, more importantly, how to
access it. Does anyone out there know how to do this?

Thanks,
Jake
 
Hi Jake,

There is some help in this skill documentation actually. I don't see a
solution for your request though. Let me explain
According to the skill document :

\(…\): A regular expression wrapped as \( form \) matches whatever
form matches, but saves the string matched in a numbered register
(starting from one, can be up to nine).
\n: A backslash followed by a digit n matches the contents of the nth
register from the current regular expression.

There is an example (From the doc also):

; The target "123 cells" does not begin with a-z/A-Z.
1. rexCompile("\\([a-z]+\\)\\.\\1") => t
2. rexExecute("abc.bc") => t
3. rexExecute("abc.ab") => nil

The compiled regular expression in line 1 would be : "match.match"
the first match will be captured into the memory/register thanks to
the grouping with the parenthesis. This captured match would then be
invoked using the regEx internal variable \1, simple as that. Line 2
evaluates to 't' because the regEx engine manages to find the same
pattern before and after the dot, This pattern was 'bc'.
Try this other example ...
rexCompile("\\([a-z]+\\)\\.\\1.*\\([a-z]+\\)\\.\\2")
rexExecute("ffffoo.foo.totobar.bar")
rexExecute("ffffoo.foo.totobar.camp")

As far as I understand, variables \1, ...\9 are valid in the regular
expression scope only. I don't see any way to print it or assign it to
a regular skill variable as I can do in Perl for example. That's my
personal understanding and I'm might be wrong.

I'm more familiar with regular expressions with Perl. Perl got
variables like $&, $`, $' and $1...9 to print out patterns related to
the matching of regular expressions:
I could run the following Perl command to get the matching from the
1st skill regExp:
PERL> print "$1\n" if $_=~m/([a-z]+)\.\1/

That was my understanding so far.

Hope this helps anyway !

Riad.
 
Hi Riad,

Thanks for your response. I have a feeling that everything you say
there is correct, maybe one of the Cadence spies can prove me wrong.
Because of this assumed issue, I wrote a PERL script to do my regular
expression processing and handshake the data back and forth in temp
files (let's all thank Cadence for the sh() function).

Regards,
Jake
 
Jake wrote:
Hi Riad,

Thanks for your response. I have a feeling that everything you say
there is correct, maybe one of the Cadence spies can prove me wrong.
Because of this assumed issue, I wrote a PERL script to do my regular
expression processing and handshake the data back and forth in temp
files (let's all thank Cadence for the sh() function).

Regards,
Jake
You can get back the content of the registers using rexSubstitute :

rexCompile("X\\(.*\\)Y\\(.*\\)Z")
=> t
rexExecute("012 X 345 Y 678 Z 9")
=> t
rexSubstitute("\\1")
=> " 345 "
rexSubstitute("\\2")
=> " 678 "
rexSubstitute("\\1\\2")
=> " 345 678 "

It is true in my opinion that regular expression support is poor in SKILL compared to perl, but it's
not useless either... :)

If we know exactly what you're after, maybe you can get the solution...

Cheers,
Stéphane
 
Salut Stéphane,

That's exactly what we were looking for. Thanks very much for this
wise advice :)
The doc shows that even the \& (or \\0) is supported, which gives the
matched pattern, that's brilliant !
Perl is of course far better than skill in terms of regular
expression. There is one thing I still don't understand with regular
Expressions in skill. I'm still wondering why an 'ignore case'
modifier like in perl/grep.... is not supported. The skill regEx
capability wimped in my esteem just because of this little tiny thing
I thought a must have for any descent regular expression engine. Does
anyone know if this is going to be enhanced in future versions of
cds ? (I haven't got the latest versions of IC 6.1.2).

Thanks again for getting this sorted out ;-)
Riad.
 
Riad KACED wrote, on 09/04/08 19:04:
Salut Stéphane,

That's exactly what we were looking for. Thanks very much for this
wise advice :)
The doc shows that even the \& (or \\0) is supported, which gives the
matched pattern, that's brilliant !
Perl is of course far better than skill in terms of regular
expression. There is one thing I still don't understand with regular
Expressions in skill. I'm still wondering why an 'ignore case'
modifier like in perl/grep.... is not supported. The skill regEx
capability wimped in my esteem just because of this little tiny thing
I thought a must have for any descent regular expression engine. Does
anyone know if this is going to be enhanced in future versions of
cds ? (I haven't got the latest versions of IC 6.1.2).

Thanks again for getting this sorted out ;-)
Riad.
A new set of functions has been added in IC6.1 with the prefix "pcre". This is
using the "PCRE" package (Perl Compatible Regular Expressions) which will make
us all a lot happier.

The rex functions in SKILL are very old, from the days when regular expressions
were simple, and had not been extended in lots of wild and interesting ways.
The rex functions were left as is for compatibility with existing code.

Andrew.
 
Andrew Beckett wrote:
A new set of functions has been added in IC6.1 with the prefix "pcre".
This is using the "PCRE" package (Perl Compatible Regular Expressions)
which will make us all a lot happier.

The rex functions in SKILL are very old, from the days when regular
expressions were simple, and had not been extended in lots of wild and
interesting ways.
The rex functions were left as is for compatibility with existing code.

Andrew.
Thanks Andrew :)
I sort of remembered you saying that the regexp support was much enhanced in 6.1, but from a quick
look couldn't find these functions... Apparently the SKILL Language User Guide makes no mention of
them (the section on regular expression describes the old rex* functions). I found them in the
Reference and Finder, though.

Cheers,
Stéphane
 
Pete nospam Zakel wrote, on 09/05/08 21:40:
In article <48c18669$1@news.cadence.com> pxhxz@cadence.com (Pete nospam Zakel) writes:
In article <1220608094_266@sicinfo3.epfl.ch> stephane.badel@REMOVETHISepfl.ch writes:
Andrew Beckett wrote:
A new set of functions has been added in IC6.1 with the prefix "pcre".
This is using the "PCRE" package (Perl Compatible Regular Expressions)
which will make us all a lot happier.
I sort of remembered you saying that the regexp support was much enhanced in 6.1, but from a quick
look couldn't find these functions... Apparently the SKILL Language User Guide makes no mention of
them (the section on regular expression describes the old rex* functions). I found them in the
Reference and Finder, though.
My Version 6.1.2 SKILL Quick Reference definitely has the pcre functions
listed. They are in the index on page 616, and the reference pages are 25-26
(in the SKILL Language Functions section right after "parseString").

Whoops -- I missed that you found them in the reference and finder.

Sounds like the User Guide needs to be updated, though.

-Pete Zakel
(phz@seeheader.nospam)

"Yesterday I was a dog. Today I'm a dog. Tomorrow I'll probably still
be a dog. Sigh! There's so little hope for advancement."

-Snoopy
I just filed CCR 598266 to get the SKILL User Guide improved.

Andrew.
 

Welcome to EDABoard.com

Sponsor

Back
Top