473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting information from String (regex, Beanshell)

11 New Member
Hello,

I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script. I want to extract information from a string, separated by newline. For this i am using regex.

The String is given:

P48534
EXP value is: e-10
Q0543
EXP value is: 4e-07


My script look like this in Beanshell:

Expand|Select|Wrap|Line Numbers
  1.  import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. Pattern pGI = Pattern.compile("(^.*?$)");
  5. Pattern pEvaLue = Pattern.compile("is: (.*)$");
  6. Matcher mGI;
  7. Matcher mEvalue;
  8. StringBuffer temp = new StringBuffer();
  9. String [] line = BlastReport.split("\n");
  10. int arraysize = line.length; 
  11.  
  12. for (int i=0; i<(arraysize-1); i+=2){
  13.     String sGI = line[i];
  14.     String sEvalue = line[i+1];    
  15.     mGI = pGI.matcher(sGI);
  16.     mEvalue = pEvalue.matcher(sEvalue);
  17.     String gi="";
  18.  
  19.     if (mGI.find()){
  20.         gi =mGI.group(1);
  21.     }
  22.     if (mEvalue.find()){
  23.         String eval = mEvalue.group(1);
  24.         if(eval.startsWith("e")){
  25.             eval= "1".concat(eval);
  26.         }
  27.         Double d = new Double (eval);
  28.         double Evalue = d.doubleValue();
  29.         if (Evalue<=0.02){
  30.             temp.append(gi + "\n");
  31.         }
  32.     }
  33. }
  34.  
  35. String result = temp.toString().trim();

The error message is: "Attempt to resolve method: matcher() on undefined variable or class name: pEvalue: at Line: 16: pEvalue .matcher(sEvalu e)"


Can someone tell me why is giving me this error and how can i fix it.

Thank you in advance,

Mokita
Aug 6 '07
10 11854
prometheuzz
197 Recognized Expert New Member
...
How can i change group 1 ([A-Z]\\d+) to catch: P00DF3 or 1234653 or Q5647GJD or A4658DF
It is not catching the ones with letters in the midle.

Thank you again,

Mokita
Try replacing "([A-Z]\\d+)" with "(\\w+)"
Aug 6 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5190
by: Markus Ernst | last post by:
Hello I have a regex problem, spent about 7 hours on this now, but I don't find the answer in the manual and googling, though I think this must have been discussed before. I try to simply extract the title and meta tags of a valid HTML page as an array: function extract_html($filename)
3
1734
by: Stephan Bour | last post by:
I have a string ³Name² in the following format: ³LastName, FirstName (Department)² that comes from Active Directory. I need to extract the FirstName from the string. Substrings are not practical for this so I used a Regex that splits the string at the first ³, ³ and again at the ³ (³. My problem is that I don¹t know how to extract the second member of the resulting array (FirstName) and assign it to another string. Using StringBuilder, as...
1
1538
by: John Seeliger | last post by:
I am pretty new to VB, so please forgive the simplistic question. This is using VB .NET Standard 2003. My form has three objects on it: a TextBox named URL, a Button named Extract and a WebBrowser named AxWebBrowser1. The goal is to have the user enter a URL in the TextBox and then hit the Extract button and then to get the links from the web page they entered. So far I have:
1
2044
by: detho | last post by:
Hi everyone... I am currently developing a streaming movie front-end for my companies' intranet. The script is done with PHP on the back-end and HTML and CSS for the front-end. Basically, the script displays the available videos in a list of links and when the user clicks on the video, the script grabs the query string information and concatinates the appropriate filename into a variable which is used to start Windows Media Player.
3
1930
by: | last post by:
I'm analyzing large strings and finding matches using the Regex class. I want to find the context those matches are found in and to display excerpts of that context, just as a search engine might. In terms of code, what's the easiest way to make that happen? The code below works fine for identifying the matches, but it doesn't try to extract the surrounding context or display it: currPageText = numberOfMatches =...
4
13966
by: Mokita | last post by:
Hello, I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script, where I want to eliminate the duplicates in an array (String). for (int k=0; k<myLength; k++){ boolean isthere=false; for (int l=0; l<sizeres; l++){ if (res.equals(my)){
10
4077
by: Dan | last post by:
I have a number of strings that represents time. 1w 2d 3h 15m 2d 3h 15m 4h 30m 45m I want to extract the number parts of my strings into separate variables for Weeks, Days, Hours and Minutes.
11
4565
by: Ebenezer | last post by:
Let's suppose I have some nodes in an XML file, with an URL attribute: <node url="mypage.php?name1=value1&foo=bar&foo2=bar2&name2=value0" /> <node url="myotherpage.php?name4=value4&foo=bar3&foo2=bar5&name2=value8" /> and so on. Let's suppose I want to retrieve this @url parameter, BUT ONLY with the values, in querystring, associated with "foo" and "foo2" (thus discarding name1, name2, name4 and every other different ones).
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.