When a pattern isn’t working the way you expect, use Log() to send pieces of the match to the JMP log. The following example shows how to debug pattern matching and rewrite a script to account for the white space between words in the phrase “the quick brown fox”.
word = Pat Repeat( Pat Not Any( " " ) );
// greedy match for one or more characters except for white space
Pat Match(
"the quick brown fox",
word >> a +
word >> b +
word >> c +
word >> d
);
Show( a, b, c, d );
a = "qu";
b = "i";
c = "c";
d = "k";
The output is probably not what you want, given the name of the pattern word. None of the words in the pattern were matched.
The Show( a, b, c, d ) expression is a good first step. If it doesn’t tell you how JMP got that answer, try inserting Log() as follows:
word = Pat Repeat( Pat Not Any( " " ) );
Pat Match(
"the quick brown fox",
(word >> a) >> Log( "a" ) +
(word >> b) >> Log( "b" ) +
(word >> c) >> Log( "c" ) +
(word >> d) >> Log( "d" )
);
Show( a, b, c, d );
0(a) the (the number 0 is the position of the match)
0(a) th (the “a” is an aribtrary identifier you supplied to the log)
2(b) e
...
4(a) quick
4(a) quic
...
word = Pat Repeat( Pat Not Any( " " ) );
gap = Pat Repeat( Pat Any( " " ), 1, 999, GREEDY );
Pat Match(
"the quick brown fox",
word >> a + gap +
word >> b + gap +
word >> c + gap +
word >> d
);
Show( a, b, c, d );
a = "the";
b = "quick";
c = "brown";
d = "fox";