Using regular expressions

Top  Previous  Next

In some situations you may find that the start or end prompts for a TelnetTask are difficult to define. This is especially true in cases where the prompts may change based on the user or system.

 

To address this issue regular expressions may be optionally used when defining the start and end prompts for a TelnetTask. To define a prompt as a regular expression first define the prompts and then use the TelnetTask#setStartPromptRegex and TelnetTask#setEndPromptRegex methods passing in a true argument to define the start and end prompts of the TelnetTask as regular expressions. While a TelnetTask is running it will use this information to determine whether the data returned by the server should be evaluated using a string comparison match or regular expression match.

 

Example

 

// define task  

TelnetTask loginTask = new TelnetTask("[Ll]ogin:","jsmith","[Pp]assword:");  

loginTask.setStartPromptRegex(true);

loginTask.setEndPromptRegex(true);      

 

In the above example both the start and end prompts are defined as regular expressions. In the case of the start prompt the TelnetTask will wait for the text "login:" or "Login:" to be returned by the server before sending the username "jsmith". It will then wait for the prompt "Password:" or "password:" before considering this TelnetTask as complete and moving on to the next TelnetTask.

 

For a tutorial on using regular expressions the following website is recommended:

 

http://www.regular-expressions.info/





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC