Introducing AutoKitten, an alternative to AutoCat

I’ve stubbed out changes in the performAction function that will update the action field with regex substitutions. It took some Innerweb hunting to pin down the proper use of regex group and the substitution format ( some docs said \1,\2 etc others $1,$2 (which is working)

AutoCat sheet entries

Line 91: says to match any digit followed by a letter and put a space inbetween
Line 92: (probably redundant):says look for a digit jammed next to ‘at’

Also specific to my situation, I get Descriptions with words jammed together, so I added another action type – replace. This action uses the string replace method to modify the target field. Unfortunately, the list I work against is rather long so the load and execution is a bit sluggish.

Modified code for performAction

 switch (rule.action) {
    case "set":
    //console.log(rule)
      //console.log(rowData)
      yap(`${rule.actionColumn}[${rowNum}]="${rule.actionValue}"`);
    //  console.log("Comparison:", rule.comparison)
      switch(rule.comparison) {
        case "matches regex":
        //const have = ${rule.actionColumn}[${rowNum}]
        //const replace = r.value.replace("/".${rule})
     //   console.log(rule);
      //console.log(rowData);
        const val=rowData[column]
        const nval=val.replace(rule.conditionValue,rule.actionValue)
        console.log(nval)
        r.setValue(rowData[column] = nval)
        break;
      default:
        r.setValue(rowData[column] = rule.actionValue);
      }
      case "replace":
        const val=rowData[column];
        const nval=val.replace(rule.conditionValue,rule.actionValue);
        console.log(nval)
        r.setValue(rowData[column] = nval);
        break;
//            yap(`${rule.actionColumn}[${rowNum}]="${rule.actionValue}"`);
//      if (rule.comparison == "match regex") {
//        rule.actionColumn.replace(rule.comparison,rule.actionValue)
//        r.setValue(rowData[column] = rule.actionColumn)
//      }
//      else {
//        r.setValue(rowData[column] = rule.actionValue);
//      }
      break;

Probably not optimal use of the data structures defined in the code, but I’ve yet to tease out the design.

1 Like

Excellent, thanks! Inspired by @ramerkw 's code, I updated the template with a new action called “replace”. It works the following way:

  • The action column must be the same as the condition column (makes sense)
  • The comparison must be one of ‘equals’, ‘matches regex’, ‘equals (ignore case)’, ‘contains’, and ‘contains (ignore case)’
  • For those cases, the replacement is carried accordingly (either string match or regex match) with case sensitivity as appropriate.

Thanks!

1 Like

@falcon8664 if you could post a sheet showing the problem, I’d be glad to look into it. Thanks!