projects/wms-framework/src/lib/baseframework/Regex/Match.ts
Class representing the Match object.
Properties |
|
Methods |
|
constructor(expression: string, target: string, option: RegexOptions)
|
||||||||||||||||
Init an instance of Match.
Parameters :
|
Private expression |
Type : string
|
Private option |
Type : RegexOptions
|
Private target |
Type : string
|
Public success |
success()
|
Return if the current match is succeded.
Returns :
boolean
True if the match is succeded. |
import { RegexOptions } from './RegexOptions';
/**
* Class representing the Match object.
*/
export class Match {
private expression: string;
private target: string;
private option: RegexOptions;
/**
* Init an instance of Match.
* @param expression The regular expression.
* @param target The target string to be evaluated.
* @param option The option.
*/
constructor(
expression: string,
target: string,
option: RegexOptions = RegexOptions.None
) {
this.expression = expression;
this.target = target;
this.option = option;
}
/**
* Return if the current match is succeded.
* @returns True if the match is succeded.
*/
public success(): boolean {
let flags = RegexOptions.toString(this.option);
if (flags != null) {
return new RegExp(this.expression, flags).test(this.target);
}
return new RegExp(this.expression).test(this.target);
}
}