You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem with the preg_match() approach is that it will return FALSE
if the pattern is malformed (and raise a warning) - this is something that
can lead to long debugging / wtf?! sessions. The Pattern class will throw
an exception.
Constant name Modifier
================ ========
CASE_INSENSITIVE i
MULTILINE m
DOTALL s
EXTENDED x
ANCHORED A
DOLLAR_ENDONLY D
ANALYSIS S
UNGREEDY U
UTF8 u
Scope of Change
A new package text.regex will be added.
Rationale
Object oriented API for regular expressions.
Functionality
The entry point class is text.regex.Pattern which is a wrapper around the
preg_*() functions in PHP.
Testing whether a pattern matches
The most common use-case is to test whether a given pattern matches.
The problem with the preg_match() approach is that it will return FALSE
if the pattern is malformed (and raise a warning) - this is something that
can lead to long debugging / wtf?! sessions. The Pattern class will throw
an exception.
Retrieving matched text
To match parts out of a string:
The results in both cases is a string-array with the contents
[ "www.example.com", "www.", "www", "com" ]
.Working with string objects
The text.regex pattern supports the lang.types.String object built-in:
Modifiers
Instead of embedding the modifiers in the pattern string, they need to be
passed to the Pattern class' compile() method as bitfield:
Further modifiers are:
This is more verbose but easier to read.
Security considerations
None.
Speed impact
Slightly slower than procedural approach.
Dependencies
PCRE extension (enabled by default)
Related documents
Lesson: Regular Expressions
PHP Manual: PCRE Functions
Concatenation of PCRE manpages
Implementation
The text was updated successfully, but these errors were encountered: