Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Tue Mar 09, 2010 12:16 am   

Trigger pattern matching on first instance of a character?
 
I have a bit of code that I use that highlights speech.
Code:
  <trigger priority="5160" id="516">
    <pattern>(*), "(*)"$</pattern>
    <value>#SUBSTITUTE {<font color=limegreen>%1,</font> ~"%2~"}</value>
  </trigger>


The problem is that it's greedy, so if someone uses a compounded speech sentence (in the following examples) they get highlighted wrong. How do I stop this at the first double-quote, given that the beginning of 'say' isn't always the same?


Current: Melissandra says, "It should say, "Never try to teach a pig to sing. It wastes your time and annoys the pig.""

Desired: Melissandra says, "It should say, "Never try to teach a pig to sing. It wastes your time and annoys the pig.""


Current: Melissandra gestures nonchalantly and states, "But, the worrisome part is what he would do with it." She considers this, then adds, "I suppose it's not such a grand idea after all."

Desired: Melissandra gestures nonchalantly and states, "But, the worrisome part is what he would do with it." She considers this, then adds, "I suppose it's not such a grand idea after all."
_________________
Unwritten Legends
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Mar 09, 2010 2:12 am   
 
(*), becomes ([%w%s]),
_________________
EDIT: I didn't like my old signature
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Mar 09, 2010 3:24 am   
 
Since you are not really change the text on the line I would use #PCOL instead of Substitute.

Code:

<trigger priority="5160" id="516">
    <pattern>^(*), "*"$</pattern>
    <value>#PCOL limegreen %x1</value>
  </trigger>
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Tue Mar 09, 2010 4:53 am   
 
Thanks to both of you for looking.

Matt, the example you gave works until we reach this situation:

Martaigne concedes, however hesitantly, "Yes, I suppose it could be worse."

Going to play with the trigger a bit more and post if I find the solution.

nexela, I tried yours as well, and it works to a degree, but leaves out the comma before the first doublequote. I'd have to play with it a bit more to make it work.

Edit: This trigger did the trick: ([%w%s,.]), "(*)"$
_________________
Unwritten Legends
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Wed Mar 10, 2010 3:42 am   
 
Code:

<trigger priority="5160" id="516">
    <pattern>^([%w%s],)* "*"$</pattern>
    <value>#PCOL limegreen %x1</value>
  </trigger>


This one should take everything into consideration
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
GenericGun
Beginner


Joined: 23 Jul 2009
Posts: 12

PostPosted: Wed Mar 10, 2010 9:31 pm   
 
This is usually where regular expressions come into play.

I think this pattern solves the problem.
Code:
^([^"]*), ".*"$


Just don't forget to select the "Regular expression" check box.
It avoids traps such as "Drizzt Do'Urden says, .. " and others similar examples.
Reply with quote
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Wed Mar 10, 2010 10:00 pm   
 
Will take a look at these tonight, thank you...
_________________
Unwritten Legends
Reply with quote
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Thu Mar 11, 2010 3:56 am   
 
Code:
^([^"]*,) ".*"$


Very close. This wound up doing the trick so far.
_________________
Unwritten Legends
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net