grep4j icon indicating copy to clipboard operation
grep4j copied to clipboard

Grep not working with simple quote

Open baubakg opened this issue 6 years ago • 0 comments

Hi,

I have been having an issue with grep regarding the following expression: ['"]

I have been trying to grep a js test file. But my expression never works in grep4j. The same expression works very well in command line grep and in various regex testers (https://regex101.com).

@Test
    public void problemGrep() {
        
        final String in_regularExpression = "test[ ]*[(]['\"]";
          
       
        File l_dir = new File("src/test/resources/rsc/toto/");
        Profile profile = ProfileBuilder.newBuilder().name("Local Directory serach")
                .filePath(l_dir.getAbsolutePath()).onLocalhost().build();
               
        GrepResults results = Grep4j.grep(Grep4j.regularExpression(in_regularExpression), Dictionary.on(profile),
                Dictionary.with(Dictionary.options(Option.recursive(),
                        Option.onlyFilesWhenRecursing("*.js"))));

        
        Assert.assertEquals(results.totalLines(), 6);
    } 

The text I have has the following code:

test("String 1", function() {
});

test("String 2", function() {
});

test("String 3", function() {
});

test("String 4", function() {
});

test("String 5", function() {
});

test('String 6', function() {
});

If I perform a grep in the command line the same expression works:

grep -e "test[ ]*[(]['\"]" testOne2.js 
test("String 1", function() {
test("String 2", function() {
test("String 3", function() {
test("String 4", function() {
test("String 5", function() {
test('String 6', function() {

Any help or suggestions are most welcome. I will change my grep to by pass the issue, but it would be nice to know why this doesn't work.

baubakg avatar Jul 14 '19 10:07 baubakg