diff --git a/src/app/degree-planner/course-search/course-search.component.ts b/src/app/degree-planner/course-search/course-search.component.ts index f2f7202c608392c4aec099c8a0753400bddabcba..747f72eeae0cd12e0ce70d6e425fdeac329193f1 100644 --- a/src/app/degree-planner/course-search/course-search.component.ts +++ b/src/app/degree-planner/course-search/course-search.component.ts @@ -132,14 +132,16 @@ export class CourseSearchComponent implements OnInit, OnDestroy { 'subject', ) as AbstractControl).valueChanges.subscribe(value => { // If the subject value is blank, or if the user is typing "all" - if (new RegExp('^([Aa]?[Ll]{0,2})$').test(value.trim())) { + if (/^(a[l]{0,2})?$/i.test(value.trim())) { this.filteredSubjects = this.subjects; return; } this.filteredSubjects = this.subjects.filter(subject => { - const search = subject.replace(/\s/g, ''); - if (search.toLowerCase().indexOf(value.toLowerCase()) === 0) { + // Make both comparisons lowercase and remove all whitespace + const formattedSubject = subject.replace(/\s/g, '').toLowerCase(); + const formattedValue = value.replace(/\s/g, '').toLowerCase(); + if (formattedSubject.indexOf(formattedValue) === 0) { return true; } return false;