title: How to define case switch to check if the case variable includes specific strings by using regex?
body: <p>I'm writing a Jenkins pipeline as a code in order to build an Android application.</p>
  
  <p>The job is configured as "GitHub Organization" which means that Jenkins is scanning the given repository, adds each branch as a job and starts a job run whenever a git commit takes place.</p>
  
  <pre><code>switch(BRANCH_NAME) {
      case "develop":
          BUILDFLAV = "Staging"
          BUILDTYPE = "Debug"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "master":
          BUILDFLAV = "Production"
          BUILDTYPE = "Release"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "release_candidate":
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "hotfix":
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "jenkins-pipeline":
          BUILDFLAV = "Staging"
          BUILDTYPE = "Debug"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "feature/upload_to_hockeyapp":
          BUILDFLAV = "Staging"
          BUILDTYPE = "Debug"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      case "feature/notifications":
          BUILDFLAV = "Staging"
          BUILDTYPE = "Debug"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          break
      default:
          println "Branch name was not set!"
          break
  }
  </code></pre>
  
  <p>Some of the branches are named like so: </p>
  
  <pre><code>hotfix/3.0.1
  release/3.2.1
  </code></pre>
  
  <p>I'd like to define a case option for these branches, something like:</p>
  
  <pre><code>case "^hotfix.*"
     code....
     break
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>case "^release\/.*"
      code...
      break
  </code></pre>
  
  <p>Edit #1:
  Here's the code after adding your part:</p>
  
  <pre><code>// Branch selection
  def showRelease(BRANCH_NAME, regex) {
      def pattern = "(release|hotfix)\\/(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)"
      switch(BRANCH_NAME) {
          case "develop":
              BUILDFLAV = "Staging"
              BUILDTYPE = "Debug"
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case "master":
              BUILDFLAV = "Production"
              BUILDTYPE = "Release"
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case "release_candidate":
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case "hotfix":
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case "jenkins-pipeline":
              BUILDFLAV = "Staging"
              BUILDTYPE = "Debug"
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case "feature/notifications":
              BUILDFLAV = "Staging"
              BUILDTYPE = "Debug"
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              break
          case ~/$regex/:
              BUILDFLAV = "Staging"
              BUILDTYPE = "Debug"
              ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
              println BRANCH_NAME
  
              break
          default:
              println "Branch name was not set!"
              break
      }
  }
  </code></pre>
  
  <p>But then, when I run the build, BRANCH_NAME is not set correctly and the next steps are unable to run because they lack the BUILDFLAV and BUILDTYPE variables.</p>
  
  <p>Edit #2:
  I've added the code you suggested:</p>
  
  <pre><code>case ~/(release|hotfix)\\/(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)/:
          BUILDFLAV = "Staging"
          BUILDTYPE = "Debug"
          ARTIFACT_NAME = "App01-${BUILDFLAV.toLowerCase()}-${BUILDTYPE.toLowerCase()}.apk"
          println "Branch Name: ${BRANCH_NAME}"
          break
  </code></pre>
  
  <p>But now I get this error:</p>
  
  <pre><code>org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.ScriptBytecodeAdapter bitwiseNegate java.lang.Object
      at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectStaticMethod(StaticWhitelist.java:190)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:142)
      at org.kohsuke.groovy.sandbox.impl.Checker$2.call(Checker.java:180)
  </code></pre>
  
  <p>But i'm not so familiar with regex use in Jenkins (groovy), how can it be done?</p>