해결책
패턴 일치 기능 사용
source = "this is a racecar and ere noon stressed desserts for Stanley Yelnats saw Anna was there";
palindrome = (Pat Regex( "[a-zA-Z][a-zA-Z ]{0,999}" )) >> firstpart + // one or more first letters
(Pat Regex( "[a-zA-Z ]{0,1}" )) + // optional middle letter
Expr( Reverse( firstpart ) ); // the tail
list = {}; // places to
positions = {}; // keep results
Pat Match(
source,
Pat Repeat( // repeat *is* a loop, within the source string
(Pat Pos() >> location + // capture current position in string
palindrome >> another + // capture the text of the palindrome match
Pat Test( // this function runs some JSL to see if the current position matches
Insert Into( list, another );// the JSL saves
Insert Into( positions, location );// two answers
1 // pattest returns 1(OK) because we are not actually testing anything...just wanted to run some JSL
)//
)
| // above adds to list, below skips forward a letter to try again
Pat Len( 1 ) // this bit is more important than it looks; it matches all the text that isn't interesting
)
);
Show( list, positions );
list = { "경주 용 자동차", "예", "정오", "스트레스가 많은 디저트", "Stanley Yelnats", "Anna saw", "ere"};
위치 = {8, 22, 26, 31, 53, 69, 84};
토론
PatRepeat는 가능한 한 패턴을 반복하는 패턴 일치 함수입니다. 원하는 패턴의 다른 인스턴스가 발견 될 때까지 한 번에 한 문자 씩 무시할 수있는 PatLen (1) 대안없이 원하지 않는 텍스트를 건너 뛸 수 없습니다.
정말 간단한 패턴을 사용할 수도 있습니다.
source = "this is a racecar and ere noon stressed desserts for Stanley Yelnats saw Anna was there";
reallysimple = "is";
list = {}; // places to
positions = {}; // keep results
Pat Match(
source,
Pat Repeat( // repeat *is* a loop, within the source string
(Pat Pos() >> location + // capture current position in string
reallysimple >> another + // capture the text of the match
Pat Test( // this function runs some JSL to see if the current position matches
Insert Into( list, another );// the JSL saves
Insert Into( positions, location );// two answers
1 // pattest returns 1(OK) because we are not actually testing anything...just wanted to run some JSL
)//
)
| // above adds to list, below skips forward a letter to try again
Pat Len( 1 ) // this bit is more important than it looks; it matches all the text that isn't interesting
)
);
Show( list, positions );
list = { "is", "is"};
위치 = {2,5};