smith
smith

Reputation: 3262

Regular expression in Perl with case insensitivity

I have the following text pattern,

os2v some text openssl-56 test Is Not founded

and need to extract the word before "test Is Not founded", i.e., in this case: openssl-56

Currently I've tried to use this regular expression:

if (m/os2v (\s+) test is NOT founded/i){
    print $1
}

But why does the code not enter the if statement?

Upvotes: 0

Views: 122

Answers (4)

Bill Ruppert
Bill Ruppert

Reputation: 9016

Get rid of the space before and after (\s+).

Upvotes: 0

Fred
Fred

Reputation: 5006

Try this one:

m/os2v .*\s([^\s]+) test is NOT founded/i

Upvotes: 1

Marcus
Marcus

Reputation: 12586

The problem is that you don't get a match since your pattern is incorrect. The following pattern would match and extract openssl-56 for you:

(\S+)(?=\stest Is Not founded)

Upvotes: 1

Quentin
Quentin

Reputation: 943537

The obvious problems are that your text doesn't include the word "Update" and \s will match whitespace.

Upvotes: 3

Related Questions