Skip to Main Content
Regular Expression Pocket Reference, 2nd Edition
book

Regular Expression Pocket Reference, 2nd Edition

by Tony Stubblebine
July 2007
Intermediate to advanced content levelIntermediate to advanced
128 pages
2h 39m
English
O'Reilly Media, Inc.
Content preview from Regular Expression Pocket Reference, 2nd Edition

Name

String

Strings support four convenience methods for pattern matching. Each method takes a pattern argument, which may be a RegExp object, or a string containing a regular expression pattern.

Methods

search(pattern)

Match pattern against the string, returning either the character position of the start of the first matching substring or -1.

replace(pattern, replacement)

Search the string for a match of pattern, and replace the matched substring with replacement. If pattern has global mode set, all matches of pattern are replaced. The replacement string may have $n constructs that are replaced with the matched text of the nth capture group in pattern.

match(pattern)

Match pattern against the string, returning either an array or -1. Element 0 of the array contains the full match. Additional elements contain submatches from capture groups. In global (g) mode, the array contains all matches of pattern with no capture group submatches.

split(pattern, limit)

Return an array of strings broken around pattern. If limit is included, the array contains at most the first limit substrings broken around pattern. If pattern contains capture groups, captured substrings are returned as elements after each split substring.

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.
Start your free trial

You might also like

PHP Advanced for the World Wide Web: Visual QuickPro Guide

PHP Advanced for the World Wide Web: Visual QuickPro Guide

Larry Ullman
PHP 5 Power Programming

PHP 5 Power Programming

Andi Gutmans, Stig Sæther Bakken, Derick Rethans

Publisher Resources

ISBN: 9780596514273Errata Page