summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki/mediawiki.RegExp.js
blob: 1da4ab4c2240ebfd41f4eaa70c7712972248be4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
( function ( mw ) {
	/**
	 * @class mw.RegExp
	 */
	mw.RegExp = {
		/**
		 * Escape string for safe inclusion in regular expression
		 *
		 * The following characters are escaped:
		 *
		 *     \ { } ( ) | . ? * + - ^ $ [ ]
		 *
		 * @since 1.26
		 * @static
		 * @param {string} str String to escape
		 * @return {string} Escaped string
		 */
		escape: function ( str ) {
			return str.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' );
		}
	};
}( mediaWiki ) );