JESS: wrestling regular expressions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JESS: wrestling regular expressions

Jason Morris
Hi Ernest,

If I run this script:

; Source string
(bind ?s "I feel super :-D")
; Pattern string
(bind ?pattern ":-D")

;; Long way
(import java.util.regex.Pattern)
(import java.util.regex.Matcher)
(bind ?objPattern (call Pattern compile ?pattern))
(bind ?objMatcher (call ?objPattern matcher ?s))
(bind ?found1 (?objMatcher find))
(printout t "API WAY = " ?found1 crlf)

;; Short way
(bind ?found2 (regexp ?pattern ?s))
(printout t "JESS WAY = " ?found2 crlf)

I get:

Jess, the Rule Engine for the Java Platform
Copyright (C) 2005 Sandia Corporation
Jess Version 7.0b1 7/11/2005

API SAYS = TRUE
JESS SAYS = FALSE

What I am I missing?

Cheers,
Jason
--
-----------------------------------------------------
Morris Technical Solutions LLC
www.morristechnicalsolutions.com
[hidden email]
phone/fax: 503.692.1088


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: wrestling regular expressions

friedman_hill ernest j
I think Jason Morris wrote:

> What I am I missing?

Nothing. Your API example uses "find()", and Jess is using "matches()";
the difference being that with matches(), the regexp has to match the
whole String. Try

(bind ?pattern ".*:-D")

---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [hidden email]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------