mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Allow JS syntax in instruct activation regex
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
import { substituteParams } from '../../../script.js';
 | 
			
		||||
import { extension_settings } from '../../extensions.js';
 | 
			
		||||
import { regexFromString } from '../../utils.js';
 | 
			
		||||
export {
 | 
			
		||||
    regex_placement,
 | 
			
		||||
    getRegexedString,
 | 
			
		||||
@@ -21,29 +22,6 @@ const regex_placement = {
 | 
			
		||||
    WORLD_INFO: 5,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Instantiates a regular expression from a string.
 | 
			
		||||
 * @param {string} input The input string.
 | 
			
		||||
 * @returns {RegExp} The regular expression instance.
 | 
			
		||||
 * @copyright Originally from: https://github.com/IonicaBizau/regex-parser.js/blob/master/lib/index.js
 | 
			
		||||
 */
 | 
			
		||||
function regexFromString(input) {
 | 
			
		||||
    try {
 | 
			
		||||
        // Parse input
 | 
			
		||||
        var m = input.match(/(\/?)(.+)\1([a-z]*)/i);
 | 
			
		||||
 | 
			
		||||
        // Invalid flags
 | 
			
		||||
        if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
 | 
			
		||||
            return RegExp(input);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create the regular expression
 | 
			
		||||
        return new RegExp(m[2], m[3]);
 | 
			
		||||
    } catch {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Parent function to fetch a regexed version of a raw string
 | 
			
		||||
 * @param {string} rawString The raw string to be regexed
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user