outaTiME / grunt-replace

Replace text patterns with applause.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regex not working as expected

grappler opened this issue · comments

I am not an expert at regex but I was able to get to get it working using a a online. This is the working copy on a testing site. http://regexr.com/3bp9s

I was not able to get the regex working when running the grunt task. The first pattern worked without issue.

        options: {
            detail: true,
            usePrefix: false,
            patterns: [
                {
                    match: /PENGU!N Gold/g,
                    replacement: 'PENGU!N'
                },
                {
                    match: /\/\*[\n\s\r\*]{5}PENGU!N extras[^]+extras-penguin-gold\.php';[\n\s\r]{2}/,
                    replacement: ''
                }
            ]
        }

I am not sure if I missing something stupid.

hi pal, wired ... i try local test with your sources and it works ...

which version of grunt-replace are you using ??

btw, usePrefix atribute is not required when use regexp for matching ...

this is my config with last release of grunt:

      complex: {
        options: {
          patterns: [
            {
              match: /PENGU!N Gold/g,
              replacement: 'PENGU!N'
            },
            {
              match: /\/\*[\n\s\r\*]{5}PENGU!N extras[^]+extras-penguin-gold\.php';[\n\s\r]{2}/,
              replacement: ''
            }
          ]
        },
        files: [
          {expand: true, flatten: true, src: ['test/fixtures/complex.txt'], dest: 'tmp/'}
        ]
      },

where complex.txt is the php file from regexr ...

Take a look:

source file and the target:

screen shot 2015-09-13 at 19 51 15

I am using the following versions on my PC.

node@4.0.0
npm@2.14.2
grunt-cli@0.1.13
├── grunt@0.4.5
├── grunt-banner@0.5.0
├── grunt-checktextdomain@1.0.0
├── grunt-contrib-copy@0.8.1
├── grunt-contrib-cssmin@0.13.0
├── grunt-contrib-imagemin@0.9.4
├── grunt-contrib-sass@0.9.2
├── grunt-contrib-uglify@0.9.2
├── grunt-contrib-watch@0.6.1
├── grunt-exec@0.4.6
├── grunt-newer@1.1.1
├── grunt-potomo@3.3.3
├── grunt-replace@0.11.0
├── grunt-rtlcss@1.6.0
├── grunt-wp-css@0.2.0
├── grunt-wp-i18n@0.5.3
└── load-grunt-config@0.17.2

mmm, i think the problem is the line ending ... in windows is different ... you could try this regexp:

      complex: {
        options: {
          patterns: [
            {
              match: /PENGU!N Gold/g,
              replacement: 'PENGU!N'
            },
            {
              match: /\/\*[\s*]{5}PENGU!N extras[^]+extras-penguin-gold\.php';[\r\n?|\n]{2}/,
              replacement: ''
            }
          ]
        },
        files: [
          {expand: true, flatten: true, src: ['test/fixtures/complex.txt'], dest: 'tmp/'}
        ]
      },

Updates ?!

Hey, sorry I was not online till now. Your solution did not seem to work. I ended up just changing the line ending to the UNIX format as the code is on GitHub and my colleagues uses a Mac.

Thank you very much for leading me to the solution and taking time to help me.

Welcome pal, thks for using grunt-replace (applause) ...