I have a string, which includes a title I want to find (-title or -t switch).
some_string -title "myTitle" some_more_string
For this I created a regular expression, which worked during development and on Android + Windows devices. After releasing the page users complained, that the page shows a blank page for iOS devices. After checking and googling it seems the mentioned title check is the cause. (Works in Chrome, but breaks in Safari: Invalid regular expression: invalid group specifier name /(?<=\/)([^#]+)(?=#*)/)
My title regular expression uses look-around assertions, which are reported bad for iOS.
import { Pipe, PipeTransform } from '@angular/core';
const titleExpression: RegExp = /(?<=\-t(itle)? ")[^"]+/;
@Pipe({
name: 'findTitle'
})
export class FindTitlePipe implements PipeTransform {
transform(value: string): string {
return value ? value.match(titleExpression)[0] : '';
}
}
However, I am a little bit lost on an alternative solution. Please advice.
Edit:
I now decided to use a split approach. (which also has yet to be improved, but that is another story)
transform(value: string): string {
const tokens: string[] = value.split(' ');
const foundAt: number = tokens.findIndex(token => ['-t', '-title'].includes(token));
return foundAt === -1 ? '' : tokens[foundAt + 1].replace('"', '');
}