Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » regex/ocl
regex/ocl [message #32156] Fri, 06 July 2007 20:48 Go to next message
Eclipse User
Originally posted by: asma.charfi.com

Hi,

I tried to use regex with ocl.
I follow "Customizing the Environment" topic in the "Advanced
Topics" in the OCL Programmer's Guide. to add new operation to String. (it
called ismatrix())
so I want to verify if my string respect or not the matrix form. (something
like that ((1,2),(3,4)) is accepted)
My constraint is like this
s.ismatrix('^\\((\\([0-9]+(,[0-9]+)*\\))(,\\([0-9]+(,[0-9]+) *\\))*\\)$')
<> null

I create a java class to verify my regex and it works perfectly.but when I
tested it with ocl it always returns false (the result of the regex is null)

I changed my pattern to simpler one s.ismatrix('\\d') <> null to verify if
my string contains a number. it also return false (independant of s)

I understand that problem in ocl when it evaluate my constraint and not in
the pattern

how can I change my pattern so that ocl gives me the right answer?

thank you
Re: regex/ocl [message #32191 is a reply to message #32156] Fri, 06 July 2007 12:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

Try this:

s.ismatrix('^\((\([0-9]+(,[0-9]+)*\))(,\([0-9]+(,[0-9]+)*\)) *\)$') <> null

In OCL string literals, backslashes have no special meaning as they do in
Java.

HTH,

Christian


charfi asma wrote:

> Hi,
>
> I tried to use regex with ocl.
> I follow "Customizing the Environment" topic in the "Advanced
> Topics" in the OCL Programmer's Guide. to add new operation to String. (it
> called ismatrix())
> so I want to verify if my string respect or not the matrix form.
> (something like that ((1,2),(3,4)) is accepted)
> My constraint is like this
> s.ismatrix('^\\((\\([0-9]+(,[0-9]+)*\\))(,\\([0-9]+(,[0-9]+) *\\))*\\)$')
> <> null
>
> I create a java class to verify my regex and it works perfectly.but when I
> tested it with ocl it always returns false (the result of the regex is
> null)
>
> I changed my pattern to simpler one s.ismatrix('\\d') <> null to verify
> if my string contains a number. it also return false (independant of s)
>
> I understand that problem in ocl when it evaluate my constraint and not in
> the pattern
>
> how can I change my pattern so that ocl gives me the right answer?
>
> thank you
Re: regex/ocl [message #32226 is a reply to message #32191] Fri, 06 July 2007 21:15 Go to previous message
Eclipse User
Originally posted by: asma.charfi.com

Hi christian,

tank you very much it works now ;-)
I passed one ower in changing the pattern I thought that problem comes from
it.:-(
next time, I will ask you questions before thinking of them ;-)
(d'ont worry I joke)

asma

"Christian W. Damus" <cdamus@ca.ibm.com> a
Previous Topic:Parsing problem.
Next Topic:Referring to all attributes of a class/element.
Goto Forum:
  


Current Time: Tue Jul 29 11:04:25 EDT 2014

Powered by FUDForum. Page generated in 0.01424 seconds