Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

javascript - if(!q || q === '*') why wildcard use as a string here?

search(q: string): Observable<any> {
if(!q || q === '*') {
  q = '';
} else {
  q = q.toLowerCase();
}

In if condition, why wildcard use as a string here? Please explain this things.

question from:https://stackoverflow.com/questions/65931123/ifq-q-why-wildcard-use-as-a-string-here

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

regular expression search for empty value, including spaces and tabs /^s*$/ . Regular expressions do not exclusively use "*", this is the number of matches from 0 to infinity.

console.log(/^s*$/.test(""));
console.log(/^s*$/.test(" "));
console.log(/^s*$/.test("*"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...