Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

What Characters Matched

Figure 21-2. 

When an expect function returns, the variable exp_buffer points to the buffer of characters that were being considered for a match. exp_buffer_end points to one character past the end of the buffer. The buffer is null-terminated. If a pattern matches, the variable exp_match is set to point into the same buffer but at the position where the pattern first matches. The variable exp_match_end points to one past the last matching character. All of these variables are character pointers.

char *exp_buffer;
char *exp_buffer_end;
char *exp_match;
char *exp_match_end;

Parenthesized subpatterns from regular expressions have their match information saved but only if the compiled form is used. Each regexp object includes the following members:

#define NSUBEXP 10

char *startp[NSUBEXP];
char *endp[NSUBEXP];

Each subpattern match is defined by a startp and endp pair. startp points to the start of the matching string, and endp points to one past the end of the matching string. startp[0] and endp[0] are identical to exp_match and exp_match_end. The remaining indices correspond to the parenthesized subpatterns in the original pattern. startp is set to 0 if the subpattern did not match.

For example, here is a fragment to print out all of the match information. In the loop, the submatch is temporarily null-terminated so that it can be printed. (The endp pointers are always ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Go

Learning Go

Jon Bodner
Command-Line Rust

Command-Line Rust

Ken Youens-Clark
Hands-on Ansible

Hands-on Ansible

Sander van Vugt

Publisher Resources

ISBN: 9781565920903Errata Page