Skip to content
Snippets Groups Projects
Commit c39b3569 authored by Alexander Rose's avatar Alexander Rose
Browse files

add escapeRegExp util

parent c2064aa3
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,9 @@ import { MolScriptBuilder } from '../../mol-script/language/builder';
const B = MolScriptBuilder;
import { Expression } from '../language/expression';
import { KeywordDict, PropertyDict, FunctionDict, OperatorList } from './types';
import { escapeRegExp } from '../../mol-util/string';
export function escapeRegExp(s: String) {
return String(s).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}
export { escapeRegExp };
// Takes a parser for the prefix operator, and a parser for the base thing being
// parsed, and parses as many occurrences as possible of the prefix operator.
......
......@@ -93,4 +93,13 @@ export function trimCharEnd(str: string, char: string) {
/** Simple function to strip tags from a string */
export function stripTags(str: string) {
return str.replace(/<\/?[^>]+>/g, '');
}
/**
* Escape string for use in Javascript regex
*
* From https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex/6969486#6969486
*/
export function escapeRegExp(str: string) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment