Question: I am creating a regular expression, in VBA that uses the JS flavor of RegEx. Here is the issue I have ran into:

Current RegEx:

```
(^6)(?:a|ab)?

```

I have a 6 followed by either nothing, an 'a' or 'ab'.

In the case of a 6 followed by nothing I want to return just the 6 using $1
In the case of a 6 followed by an 'a' or 'ab' I want to return 6B

So I need that 'B' to be optional, contingent on there being an 'a' or 'ab'.

Something to the effect of : $1B?

That of course does not work. I only want the B if the 'a' or 'ab' is present, otherwise just the $1.

Is this possible to do in a single regex pattern? I could just have 2 separate patterns, one looking for only a 6 and the other for 6'a'or'ab'... but my actual regex patterns are much more complicated and I might need several patterns to cover some of them...

Thanks for looking.

Answer: 
The matlab-related problem is that your script references a variable named `matlabbatch` without having defined it. If this is really a matlab *script*, and not part of a function, then you should `load` this variable earlier (from a `.mat` file) to have it in your base workspace, or construct it in some other way.

The act of producing a valid `matlabbatch` is `spm`-related. Have a look at [the manual](http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf) if you haven't done so. Section 39.1.4 *Automatisation of preprocessing* seems to describe what to do. If not there, somewhere earlier in the manual. As this assumes familiarity with `spm` itself, I didn't try to figure it out myself.
I stumbled across this a bit late, and while probably not still relevant to the OP, I thought I would offer an answer in case someone else runs across this. The problem is likely that the call to spm\_jobman at line 17 spm\_jobman('run', matlabbatch) is written prior to defining matlabbatch. There is no need to load a prior .mat file; the code offered should define matlabbatch properly with the structure intact. You just can't call spm\_jobman to run it until after the declarations are made. Move that line to the bottom of the script.