Well, the pattern matchin will have to be done twice.
With your method you can save the repeated pattern compilation
by creating a static Pattern p = Pattern.compile().
The pattern suggests that it might be possible to do a String.split on
"," and take the String[3] as your group. Also, the pattern itself
might be improved by using
"3240, Z4 Ph. Reach,[^,]*, ([^]*), ohm, [^,]*, [^,]*, [^,]*"
to avoid repeated backtracking (provided ',' is indeed a true separator).
-W
On 27/08/2012, Qiteng Hong <q.hong(a)strath.ac.uk> wrote:
Hi Laune:
Thanks for your comments and suggestions.
Actually that's what I am doing . firstly match the string in the LHS and
then on the RHS I call the java method parsingZ4_Ph_Reach()--details as
followed I took it as a compromised solution but not sure how it will
influence the efficiency. Any idea about this?
public double parsingZ4_Ph_Reach(String line){
> String regx="3240, Z4 Ph. Reach, .*, (.*), ohm, .*,
> .*, .*";
> Pattern
> p=Pattern.compile(regx,Pattern.CASE_INSENSITIVE);
> Matcher m =p.matcher(line);
> if(m.matches()){
> return Double.parseDouble(m.group(1));
> }
> return 0;
> }
Thx
----------------------------------------------------------------------------------------------
QITENG HONG
PhD Research Student
Advanced Electrical Systems Group
Institute of Energy and Environment
Department of Electronic and Electrical Engineering
University of Strathclyde
Glasgow G1 1XW
The University of Strathclyde is a charitable body, registered in Scotland,
number SC015263
________________________________________
From: rules-users-bounces(a)lists.jboss.org
[rules-users-bounces(a)lists.jboss.org] On Behalf Of Wolfgang Laun
[wolfgang.laun(a)gmail.com]
Sent: 27 August 2012 17:26
To: Rules Users List
Subject: Re: [rules-users] Extracting data from strings(regular expression)
Although there is the "matches" operator, Drools isn't a sophisticated
regular expression engine.
Once you have matched a fact with a String line that matches some
regular expression, you'll have to reapply the regular expression on
the right hand side so that you can extract the string matching group
1. Or use simple String methods to extract this information, now that
you know that the string has a certain pattern.
-W
On 27/08/2012, abing19881226 <q.hong(a)strath.ac.uk> wrote:
> Hi:
> I am trying to match a string to my regular expression and then capture
> certain groups from the string.
> I know previously there is no such feature , but I am just wondering if
> there is one now?
>
> Basically , what am trying to do is, insert strings into the session,
> and
> carry out the reasoning to see if matches a certain regular expression.
> In JAVA I did it as this:
>
>
> public double parsingZ4_Ph_Reach(String line){
> String regx="3240, Z4 Ph. Reach, .*, (.*), ohm, .*,
> .*,
> .*";
> Pattern
> p=Pattern.compile(regx,Pattern.CASE_INSENSITIVE);
> Matcher m =p.matcher(line);
> if(m.matches()){
> return Double.parseDouble(m.group(1));
> }
> return 0;
> }
>
>
> The purpose is to extract the data in the strings using drools.
> Could you please give me some idea I I could do that in Drools?
> Many thx.
>
>
>
>
>
> --
> View this message in context:
>
http://drools.46999.n3.nabble.com/Extracting-data-from-strings-regular-ex...
> Sent from the Drools: User forum mailing list archive at
Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users