423,680 Members | 2,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,680 IT Pros & Developers. It's quick & easy.

Beanshell string manipulation

P: 1
Hi All,

I'm newwith beanshell and i need to write a script that extracts an information from a string and if possible returns another string with the extracted pattern inside.
for example I have in inputs something like this:
<ns2:runResponse xmlns:ns2="http://soaplab.org/typedws" xmlns:ns3="http://ebi.ac.uk/fproml">[phylogeny_molecular_sequence.fproml]_797619cb.12900bfceba._650</ns2:runResponse>

what i want to extract is the id between > and < , in this case :
that is the only part that changes everytime.
After that I would obtain a string with that id a new string like:
<jobId xmlns="http://soaplab.org/typedws"><jobId xmlns="">[phylogeny_molecular_sequence.fproml]_797619cb.12900bfceba._650</jobId></jobId>

I tried to use the code in this way:

Expand|Select|Wrap|Line Numbers
  1. import java.util.regex.Pattern;
  2. import java.util.regex.Matcher;
  4. StringBuffer temp = new StringBuffer();
  5. String information="";
  6. // regular expression to extract only the sequence description
  7. Pattern pattern = Pattern.compile ("([phylogeny_molecular_sequence.fproml])(...........................)*(</ns2:runResponse>)");
  8. Matcher matcher = pattern.matcher(inputs);
  10. while(matcher.find()){
  11.     information=matcher.group(2);
  12.     temp.append(information);
  13. }
  15. // Output sequence description
  16. String result = temp.toString();
but probably there is a smarter method to extract the same info,
and using something like
String result = temp.toString("<jobId xmlns=\"http://soaplab.org/typedws\"><jobId xmlns=\"\">" + information + "</jobId></jobId>");
to recreate the new output string doesn't work

thank you for any help
Jun 16 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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