all files / common/util/ RegExpUtils.ts

85.71% Statements 6/7
50% Branches 1/2
66.67% Functions 2/3
83.33% Lines 5/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                              16×     16×      
/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
 
export class RegExpUtils {
 
    /**
     * escape all regexp special chars.
     *
     * @param value
     * @returns the regexp special chars escaped string
     */
    public static escapeRegExp(value: string): string {
        Iif (!value) {
            return value;
        }
        return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
    }
}