Platforms to show: All Mac Windows Linux Cross-Platform

NSDataDetectorMBS class

Super class: NSRegularExpressionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
A specialized regular expression object that matches natural language text for predefined data patterns.
Example
// create detector for links and emails
Var types As Integer = NSTextCheckingResultMBS.NSTextCheckingTypeLink
Var Error As NSErrorMBS
Var DataDetector As New NSDataDetectorMBS(types, error)

Var s As String = "Email us at john@mbs.test today!"

// look for the links now
Var m() As NSTextCheckingResultMBS = DataDetector.matches(s, 0)

// show first link
Var r As NSTextCheckingResultMBS = m(0)
MsgBox r.URL

Currently the NSDataDetectorMBS class can match dates, addresses, links, phone numbers and transit information.
(links includes email addresses)

The results of matching content is returned as NSTextCheckingResultMBS objects. However, the NSTextCheckingResultMBS objects returned by NSDataDetectorMBS are different from those returned by the base class NSRegularExpressionMBS. Results returned by NSDataDetector will be of one of the data detectors types, depending on the type of result being returned, and they will have corresponding properties. For example, results of type NSTextCheckingTypeDate have a date, timeZone, and duration; results of type NSTextCheckingTypeLink have a URL, and so forth.
Subclass of the NSRegularExpressionMBS class.

Super class NSRegularExpressionMBS

Matching Options

Constant Value Description
MatchingAnchored 4 Specifies that matches are limited to those at the start of the search range. See enumerateMatches for a description of the constant in context.
MatchingReportCompletion 2 Call the Block once after the completion of any matching. This option has no effect for methods other than enumerateMatches. See enumerateMatches for a description of the constant in context.
MatchingReportProgress 1 Call the Block periodically during long-running match operations. This option has no effect for methods other than enumerateMatches. See enumerateMatches for a description of the constant in context.
MatchingWithoutAnchoringBounds 16 Specifies that ^ and $ will not automatically match the beginning and end of the search range, but will still match the beginning and end of the entire string. This constant has no effect if the search range contains the entire string. See enumerateMatches for a description of the constant in context.
MatchingWithTransparentBounds 8 Specifies that matching may examine parts of the string beyond the bounds of the search range, for purposes such as word boundary detection, lookahead, etc. This constant has no effect if the search range contains the entire string. See enumerateMatches for a description of the constant in context.

Progress

Constant Value Description
MatchingCompleted 2 Set when the Block is called after matching has completed.
MatchingHitEnd 4 Set when the current match operation reached the end of the search range.
MatchingInternalError 16 Set when matching failed due to an internal error.
MatchingProgress 1 Set when the Block is called to report progress during a long-running match operation.
MatchingRequiredEnd 8 Set when the current match depended on the location of the end of the search range.

Options

Constant Value Description
RegularExpressionAllowCommentsAndWhitespace 2 Ignore whitespace and #-prefixed comments in the pattern.
RegularExpressionAnchorsMatchLines 16 Allow ^ and $ to match the start and end of lines.
RegularExpressionCaseInsensitive 1 Match letters in the pattern independent of case.
RegularExpressionDotMatchesLineSeparators 8 Allow . to match any character, including line separators.
RegularExpressionIgnoreMetacharacters 4 Treat the entire pattern as a literal string.
RegularExpressionUseUnicodeWordBoundaries 64 Use Unicode TR#29 to specify word boundaries (otherwise, traditional regular expression word boundaries are used).
RegularExpressionUseUnixLineSeparators 32 Treat only \n as a line separator (otherwise, all standard line separators are used).

This class has no sub classes.

Some methods using this class:

Some examples using this class:

Blog Entries

Videos

Release notes


The items on this page are in the following plugins: MBS MacCocoa Plugin.


NSCustomTouchBarItemMBS   -   NSDateComponentsMBS


The biggest plugin in space...