 |
XonDK Apprentice
Joined: 01 Dec 2006 Posts: 178
|
Posted: 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. |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
|
 |
XonDK Apprentice
Joined: 01 Dec 2006 Posts: 178
|
Posted: 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. |
|
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
 |
chris-74269 Magician
Joined: 23 Nov 2004 Posts: 364
|
Posted: 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
|
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: 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 |
|
|
 |
|
|
|