Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSRegularExpressionMBS class.

NSRegularExpressionMBS.Constructor(script as string, options as Integer, byref error as NSErrorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an initialized NSRegularExpression instance with the specified regular expression pattern and options.

pattern: The regular expression pattern to compile.
options: The regular expression options that are applied to the expression during matching. See NSRegularExpressionOptions for possible values.
error: An out value that returns any error encountered during initialization. Returns an NSErrorMBS object if the regular expression pattern is invalid; otherwise returns nil.

Returns an instance of NSRegularExpressionMBS for the specified regular expression and options

NSRegularExpressionMBS.copy as NSRegularExpressionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of the object.

NSRegularExpressionMBS.enumerateMatches(text as string, options as Integer, range as NSRangeMBS = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Enumerates the string allowing the event to handle each regular expression match.

Calls enumerateMatch event.

text: The string.
options: The matching options to report. See MatchingOptions for the supported values.
range: The range of the string to test.

This method is the fundamental matching method for regular expressions and is suitable for overriding by subclassers. There are additional convenience methods for returning all the matches as an array, the total number of matches, the first match, and the range of the first match.

By default, the event iterator method calls the event precisely once for each match, with a non-nil result and the appropriate flags. The client may then stop the operation by setting the contents of stop to true. The stop argument is an out-only argument. You should only ever set this Boolean to true within the event.

If the MatchingReportProgress matching option is specified, the event will also be called periodically during long-running match operations, with nil result and MatchingProgress matching flag set in the event’s flags parameter, at which point the client may again stop the operation by setting the contents of stop to true.

If the MatchingReportCompletion matching option is specified, the event object will be called once after matching is complete, with nil result and the MatchingCompleted matching flag is set in the flags passed to the event, plus any additional relevant MatchingFlags from among MatchingHitEnd, MatchingRequiredEnd, or MatchingInternalError.

MatchingProgress and MatchingCompleted matching flags have no effect for methods other than this method.
The MatchingHitEnd matching flag is set in the flags passed to the event if the current match operation reached the end of the search range. The MatchingRequiredEnd matching flag is set in the flags passed to the event if the current match depended on the location of the end of the search range.

The MatchingFlags matching flag is set in the flags passed to the event if matching failed due to an internal error (such as an expression requiring exponential memory allocations) without examining the entire search range.

The MatchingAnchored, MatchingWithTransparentBounds, and MatchingWithoutAnchoringBounds regular expression options, specified in the options property specified when the regular expression instance is created, can apply to any match or replace method.
If MatchingAnchored matching option is specified, matches are limited to those at the start of the search range.
If MatchingWithTransparentBounds matching option is specified, matching may examine parts of the string beyond the bounds of the search range, for purposes such as word boundary detection, lookahead, etc.

If MatchingWithoutAnchoringBounds matching option is specified, ^ 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.

MatchingWithTransparentBounds and MatchingWithoutAnchoringBounds matching options have no effect if the search range covers the entire string.

NSRegularExpressionMBS.firstMatch(text as string, options as Integer, range as NSRangeMBS = nil) as NSTextCheckingResultMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the first match of the regular expression within the specified range of the string.

text: The string to search.
options: The matching options to use. See NSMatchingOptions for possible values.
range: The range of the string to search.

Returns an NSTextCheckingResultMBS object. This result gives the overall matched range via its range property, and the range of each individual capture group via its rangeAtIndex: method. The range {NSNotFound, 0} is returned if one of the capture groups did not participate in this particular match.

This is a convenience method that calls enumerateMatches.

NSRegularExpressionMBS.matches(text as string, options as Integer, range as NSRangeMBS = nil) as NSTextCheckingResultMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an array containing all the matches of the regular expression in the string.

text: The string to search.
options: The matching options to use. See Matching Options for possible values.
range: The range of the string to search.

Returns an array of NSTextCheckingResultMBS objects. Each result gives the overall matched range via its range property, and the range of each individual capture group via its rangeAtIndex: method. The range {NSNotFound, 0} is returned if one of the capture groups did not participate in this particular match.

This is a convenience method that calls enumerateMatches passing the appropriate string, options, and range.

NSRegularExpressionMBS.numberOfMatches(text as string, options as Integer, range as NSRangeMBS = nil) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the number of matches of the regular expression within the specified range of the string.

text: The string to search.
options: The matching options to use. See Matching Options for possible values.
range: The range of the string to search.

Returns the number of matches of the regular expression.

This is a convenience method that calls enumerateMatches.

NSRegularExpressionMBS.rangeOfFirstMatch(text as string, options as Integer, range as NSRangeMBS = nil) as NSRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the range of the first match of the regular expression within the specified range of the string.

string: The string to search.
options: The matching options to use. See Matching Options for possible values.
range: The range of the string to search.

Returns the range of the first match. Returns {NSNotFound, 0} if no match is found.

This is a convenience method that calls enumerateMatches.

NSRegularExpressionMBS.replaceMatches(byref text as string, options as Integer, range as NSRangeMBS = nil, template as String) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces regular expression matches within the mutable string using the template string.

text: The Text to search and replace values within.
options: The matching options to use. See NSMatchingOptions for possible values.
range: The range of the string to search.
template: The substitution template used when replacing matching instances.

Returns the number of matches.

See Flag Options for the format of template.

NSRegularExpressionMBS.replacementStringForResult(result as NSTextCheckingResultMBS, text as string, offset as Integer, template as String) as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Used to perform template substitution for a single result for clients implementing their own replace functionality.

result: The result of the single match.
text: The string from which the result was matched.
offset: The offset to be added to the location of the result in the string.
template: See Flag Options for the format of template.

Returns a replacement string.

For clients implementing their own replace functionality, this is a method to perform the template substitution for a single result, given the string from which the result was matched, an offset to be added to the location of the result in the string (for example, in cases that modifications to the string moved the result since it was matched), and a replacement template.
This is an advanced method that is used only if you wanted to iterate through a list of matches yourself and do the template replacement for each one, plus maybe some other calculation that you want to do in code, then you would use this at each step.

NSRegularExpressionMBS.stringByReplacingMatches(text as string, options as Integer, range as NSRangeMBS = nil, template as String) as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Regular Expressions MBS MacCocoa Plugin 21.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string containing matching regular expressions replaced with the template string.

text: The string to search for values within.
options: The matching options to use. See Matching Options for possible values.
range: The range of the string to search.
template: The substitution template used when replacing matching instances.

Returns a string with matching regular expressions replaced by the template string.

See Flag Options for the format of template.

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


The biggest plugin in space...