Regex in grunt-version

I’m trying to use the grunt-version to bump the version of my PHP WordPress Plugin project. For a long time I tried and tried, but failed.

In my plugin file example.php I have a PHP variable denoting the project version:

public $version = '0.3.4';

I need to match the string so that I can bump the version here too.

I tried:

prefix: 'publics$versions='

As of regex101.com it matches the string completely. The version number portion is dealt with the grunt plugin completely.

But the grunt version::patch says:

Pattern not found in file
Path: example.php
Pattern: /(publics$versions=s)([0-9a-zA-Z-_+.]+)/g

So I modified the pattern to:

prefix: 'public/s$version/s=/s'

But it’s not matching:

Pattern: /(public/s$version/s=/s)([0-9a-zA-Z-_+.]+)/g

Nonetheless, the following pattern is working fine in the same file:

prefix: 'Version:\s+'

And bumping version nicely in plugin header:

Version: 0.3.4

So I tried:

prefix: 'public $version =\s+'

But no luck:

Pattern: /(public $version =s+)([0-9a-zA-Z-_+.]+)/g

FYI, my Gruntfile declaration is like below:

version: {
    pluginVersion: {
        options: {
            prefix: 'Version:\s+'
        },
        src: [
            'example.php'
        ]
    },
    pluginVariable: {
        options: {
            prefix: 'public $version =\s+'
        },
        src: [
            'example.php'
        ]
    },
    packageJson: {
        src: [
            'package.json'
        ]
    }
},

Read more here: Regex in grunt-version

Leave a Reply

Your email address will not be published. Required fields are marked *