PhantomScript v1.7 Reference - Copyright © 2006 P1 Systems Incorporated. All Rights Reserved.

Prev | Next | Users Guide | PhantomScript Reference | P1 Systems


Strings

RegExGrep

Syntax

RegExGrep <reslist> <string> <regex> [MatchCase]

Description

Searches a string for a substring matching a specified regular expression and returns a list containing extracted information.

Parameters

<reslist>

A Variable that will receive the result list.

<string>

The string to search.

<regex>

The regular expression to match (see the remarks section for details).

Matchcase

Optional. If this parameter is included, matching is case-sensitive.

Remarks

Example: Suppose the regex string is"Account Number: (.*), Expires: (.*) ". The parenthesized subexpressions are capture subexpressions. Text matching the captured subexpressions returned in the result list. Suppose we applied this pattern to this string:"John Smith - Account Number: 23456, Expires: 2/2000 Zipcode: 98104". This would produce the following result list:"John Smith - ,23456,2/2000,Zipcode: 98104".

If no match is found, an empty list is returned.

A similar but simpler function is provided by the PatternMatch statement.

Example

Global pat = "<href=(.*)>"
RegExGrep rlist str pat
While ItemCount rlist > 2 Loop
Log Item2 rlist
str = Item4 rlist
RegExGrep rlist str pat
EndLoop

The above script fragment logs the targets of all HTML hypertext references in the str string. The string assigment within the loop removes the text up to and including the previous match from the string so that further matches can be found.



Prev | Next | Users Guide | PhantomScript Reference | P1 Systems

PhantomScript v1.7 Reference - Copyright © 2006 P1 Systems Incorporated. All Rights Reserved.