The technical details
I want to EXTRACT values from a text file containing parameter names and values. For each line that starts with "request.config." (there are empty lines, lines with comments, etc. which I don't want to extract anything from) I want to extract these values (in bold) :
request.config.my_param_1 = "some random string";
I thought the best way to do this might be using REGEX, but how can I do this?
I thought there would be something like a regular expression that would extract the 2 values request.config.${1} = ${2};
and retrieve ${1} and ${2}, for each line, but only if it matches.
I tried experimenting but it did not work:
<cfset str = "request.config.MY_PARAM_NAME = 'The parameter VALUE!!';">
<cfset arrSearch = rematch("^request.config.(.*?) = (.*?);$", str) >
<cfdump var="#arrSearch#" label="Extracted values">
Unfortunately, this code gives me the FULL STRING I already had, I just want the 2 extracted values!
Some META : WHAT I'm trying to do
I am building a web app that lets end-users modify some application parameters which are stored in a params_file.cfm. Instead of having developpers change the variables manually in the file, we want to be able to do it from within the application.
My application first makes an AJAX call to the backend, which reads the params file, get all the data pairs (param_name, param_value and possibly later on a param_description) and returns them as JSON to populate my list for which I have an autocomplete tool to search them by name (Typeahead.js for the curious). When I select a parameter name the value appears along with some controls to modify them (the controls depend on the data type, JQuery is used to determine the type).
The thing is the param_value can take many forms.. because this params file is maintained by different people it can have different syntax. For example a boolean can be stored as "TRUE", 'true', TRUE, true (you get the idea).
Since the SerializeJSON handles the types (booleans, numbers, strings) I thought my REGEX should return me the text WITHOUT the quotes (single or double) but I am having trouble crafting that expression.
I got
<cfset match = REFind("^request\.config\.(\S+) = ['|""]?(.*)['|""]?;$", str, 1, "Yes")>
and I tested it with request.config.my_param_1 = 'MYTEST123';
and it ONLY REMOVES THE FIRST SINGLE QUOTE, for some reason the expression returns me MYTEST123'
when I don't want any surrounding quote. I need HELP with my REGEX