user2454455
user2454455

Reputation:

How to match the pattern regardless of the number of whitespaces

Not good in regexp, how can i match the pattern regardless of how many whitespaces there is?

var pattern = / void main$/;  //here

var pool1 = "abdodfo void main";
var pool2 = "abdodfo   void     main";

console.log(pattern.test(pool1)); //  true
console.log(pattern.test(pool2)); //  must also be true

Upvotes: 1

Views: 54

Answers (2)

tckmn
tckmn

Reputation: 59273

var pattern = /void\s+main$/;

Use \s for whitespace, and + for "one or more."

Upvotes: 2

Nir Alfasi
Nir Alfasi

Reputation: 53525

Change the pattern to: /\s+void\s+main$/

Upvotes: 3

Related Questions