Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions again

Status
Not open for further replies.

ADoozer

Programmer
Joined
Dec 15, 2002
Messages
3,487
Location
AU
having a stinker of a time writing an expression. ive managed to bodge it to work but i know it can be better.

Code:
RE.Pattern = "(Deal|Show|Muck)(Cards|Flop|Turn|River)([\s\S]*?)<Card value=""([\s\S]*?)</Action>"

(values im looking for are DealCards, DealFlop, DealTurn, DealRiver, ShowCards, MuckCards)

now occasionaly MuckCards will not have any data after it, but it is still added because it sees a </Action> later on in the file.

this is an example of data i need to catch
Code:
<Action seq="3" type="DealCards" seat="7">
         <Card value="2" suit="Diamonds"/>
         <Card value="2" suit="Spades"/>
      </Action>

Code:
<Action seq="14" type="DealFlop">
         <Card value="7" suit="Hearts"/>
         <Card value="6" suit="Hearts"/>
         <Card value="King" suit="Diamonds"/>
      </Action>

Code:
<Action seq="26" type="DealRiver">
         <Card value="10" suit="Diamonds"/>
      </Action>

data i dont want to catch

Code:
<Action seq="29" type="MuckCards" seat="7"[b]/>[/b]

data my RE pattern is currently catching, which is bad

Code:
<Action seq="34" type="MuckCards" seat="4"/>
      <Action seq="35" type="Check" seat="1"/>
      <Action seq="36" type="Check" seat="2"/>
      <Action seq="37" type="DealTurn">
         <Card value="5" suit="Clubs"/>
      </Action>

any help will save my sanity.. thanks in advance

If somethings hard to do, its not worth doing - Homer Simpson
 
Try this.
[tt]
re.Pattern = "<Action .*? type=""(Deal|Show|Muck)(Cards|Flop|Turn|River)""[^</]*>([\s\S]*?)<Card value=""([\s\S]*?)</Action>"[/tt]
 
Much as I like the power of Regular Expressions, given that the text appears to be XML would it not be easier to parse it using the XML libraries?
 
hypetia.. seems to have done the trick.

strongm.. yes it is XML stored in an SQLite DB. im getting most of the data i need (using DOMDocument and IXMLDOMNodeList). however when i started the project i didnt know the exact syntax, and so to avoid rewriting the hole code i just need to bodge this section.

If somethings hard to do, its not worth doing - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top