Message Boards Message Boards

1
|
3747 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

String matching with Cases

Posted 11 years ago
I'm trying to get the following to return "pfam03571" from the XML structure.
Cases[
  XMLElement[
    "myelem", {}, {XMLElement[
    "INSDQualifier_value", {}, {"Peptidase family M49; pfam03571"}]}],
    XMLElement[_, {}, {___~~x:RegularExpression["pfam\\d+"]~~___}]:>x,
  Infinity]
This doesn't work. Is this possible without extracting all XMLElement values (I don't know the element tag name) and using StringCases?
POSTED BY: Zach Bjornson
2 Replies
This seems to work:
In[22]:= Cases[
   XMLElement[
     "myelem", {}, {XMLElement[
     "INSDQualifier_value", {}, {"Peptidase family M49; pfam03571"}]}],
   XMLElement[_, {}, {x_String}] /; StringMatchQ[x, RegularExpression[".+pfam\\d+"]] :> x, Infinity] 
Out[22]= {"Peptidase family M49; pfam03571"}
POSTED BY: Jeffrey Bryant
Maybe this:
Cases[
XMLElement["myelem", {}, {XMLElement["INSDQualifier_value", {}, {"Peptidase family M49; pfam03571"}]}]
,
x:_String /; StringMatchQ[x, ___ ~~ "pfam" ~~ DigitCharacter ..] :> StringSplit[x, "; "][[-1]], Infinity]

returning this:
{"pfam03571"}
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract