by pmk65 » Sat Jan 14, 2017 5:51 pm
In plain Javascript or PHP, it matches empty string as expected.
- Code: Select all
var a = "";
if (/^(\s*)(.*)$/.test(a)) {
// Successful match
alert(1)
} else {
// Match attempt failed
alert(0)
}
- Code: Select all
"^" + // Assert position at the beginning of the string
"(" + // Match the regular expression below and capture its match into backreference number 1
"\\s" + // Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
"*" + // Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"(" + // Match the regular expression below and capture its match into backreference number 2
"." + // Match any single character that is not a line break character
"*" + // Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"$" // Assert position at the end of the string (or before the line break at the end of the string, if any)
Changing \s* to \s*? didn't help. Still no match on empty lines.
There are 10 types of people in the world: Those who understand binary and those who don't.