Search code examples
regexvariablestritium

How do I mutate a tritium variable string?


I've fetched the entire list of classes from the body into a variable like so:

$page_code = fetch("self::body/@class")

But I only want to grab one class out. I tried using replace() and a regex on the variable contents but I think something's up with my syntax:

$page_code {
  text() {
    replace(/[^A-Z]*/, '')
  }
  log("@@@@@@@@@@@@@@ page code is " + $page_code)
}

Solution

  • I think the code you want is:

    $page_code {
      replace(/[^A-Z]*/, '')
    }
    log("@@@@@@@@@@@@@@ page code is " + $page_code)
    

    Since $page_code is already a string, you don't need to open up a text() scope. Also, the log() statement should be outside, or else it will just log the current value of $page_scope.

    See it here: http://tester.tritium.io/8ccb7ef99a0fd2fcbd60bd74cc137b040f57555e