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 :
[phylogeny_molecular_sequence.fproml]_797619cb.12900bfceba._650
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
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- StringBuffer temp = new StringBuffer();
- String information="";
- // regular expression to extract only the sequence description
- Pattern pattern = Pattern.compile ("([phylogeny_molecular_sequence.fproml])(...........................)*(</ns2:runResponse>)");
- Matcher matcher = pattern.matcher(inputs);
- while(matcher.find()){
- information=matcher.group(2);
- temp.append(information);
- }
- // Output sequence description
- String result = temp.toString();
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
regards!