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
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Fri Nov 21, 2008 4:54 am   

Feature request: %matchrev or %revmatch somesuch
 
I don't see how this can be done as it is.
in short it would work exactly like %match but would instead of checking for the first instance would look for the last instance of the pattern asked to look for
or maybe an option within %match?

%match(%line,"in %w",-1)
-1 for reverse
0 or not there for normal first instance
2+ for the second third fourth and so on instance where the pattern matches.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Nov 21, 2008 5:15 am   
 
You have a number of options, the easiest of which is probably to use one of the functions similar to %match that uses regexes (%regex, %subregex) and building a regex that matches the last possible match on the line. Without seeing the specific text of your example, we can't do that for you.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Fri Nov 21, 2008 7:07 am   
 
Well what I need is basicly.
long line of text that may or may not have the word 'in' in it, what I want is the last in, and the char number when it begins.

I've made a looping function around it as it is now.

Basicly it would work in any sentance, that would need to find the last instance of anything rather then the first as %match does.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Nov 21, 2008 8:09 am   
 
If you need the last one then a something like this will do the trick.

#call %match(@MyLongLine, "(*)in", $result)
#print $result

If you need to check the second or third just repeat the pattern. For example
#call %match(@MyLongLine, "(*)in*in", $result)

The reason this works is because the standard zScript '*' pattern is greedy.
_________________
Asati di tempari!
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Fri Nov 21, 2008 4:02 pm   
 
you can also do something like %item(%1,%numwords(%1)). Which would take the item # of the last word
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Fri Nov 21, 2008 10:53 pm   
 
Tech has pretty much the right way of doing the last instance. What you are actually doing with the text would decide how you would want to configure the regex.

You say you want the position of the word "in" so the exact regex would be
#LOCAL InPos
#CALL %regex(%line,".*(?=\bin\b)",$InPos)
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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