How do I configure Jenkins to trigger on a pull request based on the Git branch's name? I want pull requests to Git where the target is master and the source has a string "foo" to trigger a Jenkins build.

If this string "foo" appears in the source branch's name when there is a pull request, I want the Jenkins build to start.

The only way I can think of doing something this sophisticated is to put the logic into a Jenkins pipeline file.  Is there a plugin or supported way of making this work?  I am not using Github.

Is there a way to filter any branch that does not have "foo" in it?  How do I trigger a build based on a pull request?  I tried doing this by itself (without the search for the pattern "foo"), and even that failed.  There were no errors, but I know Jenkins was authenticating to Git with the credentials I configured in Jenkins.  The Jenkins job would not run when the conditions I configured were met.
Using a multi-branch pipeline you have several different ways of filtering branches, take for instance a regular expression for "foo". In order to use this job type, you must create a Jenkinsfile in your repo with build instructions using the scripted or declarative syntax. The term pull request is typically synonymous with services like Github and Bitbucket. 

  

You can also filter within the pipeline itself using declarative syntax:

when {changeRequest branch: "foo.*", comparator: 'REGEXP' }


And also scripted syntax:

if (env.BRANCH_NAME ==~ /foo.*/){  
    ...
}