Message Boards Message Boards

GROUPS:

String matching with Cases

Posted 6 years ago
1176 Views
|
2 Replies
|
4 Total Likes
|
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?
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"}
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"}
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