|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: 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." |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Mar 09, 2010 2:12 am |
(*), becomes ([%w%s]),
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: 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>
|
|
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: 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,.]), "(*)"$ |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: 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 |
|
|
|
GenericGun Beginner
Joined: 23 Jul 2009 Posts: 12
|
Posted: Wed Mar 10, 2010 9:31 pm |
This is usually where regular expressions come into play.
I think this pattern solves the problem.
Just don't forget to select the "Regular expression" check box.
It avoids traps such as "Drizzt Do'Urden says, .. " and others similar examples. |
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: Wed Mar 10, 2010 10:00 pm |
Will take a look at these tonight, thank you...
|
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: Thu Mar 11, 2010 3:56 am |
Very close. This wound up doing the trick so far. |
|
|
|
|
|