outaTiME / grunt-replace

Replace text patterns with applause.
MIT License
411 stars 47 forks source link

Regex not working as expected #83

Closed grappler closed 9 years ago

grappler commented 9 years ago

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.

outaTiME commented 9 years ago

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 ...

outaTiME commented 9 years ago

Take a look:

source file and the target:

screen shot 2015-09-13 at 19 51 15
grappler commented 9 years ago

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
outaTiME commented 9 years ago

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/'}
        ]
      },
outaTiME commented 9 years ago

Updates ?!

grappler commented 9 years ago

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.

outaTiME commented 9 years ago

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