replace | export const removeAnchors = (regexString: string) => {
return regexString.replace(/^\^|\$$/g, '')
}
{ input: '^a^b$c$d$', expected: 'a^b$c$d' },
{ input: 'a^b$c$d$', expected: 'a^b$c$d' },
{ input: '^a^b$c$d', expected: 'a^b$c$d' },
{ input: 'a^b$c$d', expected: 'a^b$c$d' },
{ input: '^a^b$c$d$e$', expected: 'a^b$c$d$e' },
{ input: 'a^b$c$d$e$', expected: 'a^b$c$d$e' },
{ input: '^a^b$c$d$e', expected: 'a^b$c$d$e' },
{ input: 'a^b$c$d$e', expected: 'a^b$c$d$e' },
{ input: '^a^b$c$d$e$f$', expected: 'a^b$c$d$e$f' },
{ input: 'a^b$c$d$e$f$', expected: 'a^b$c$d$e$f' },
{ input: '^a^b$c$d$e$f', expected: 'a^b$c$d$e$f' },
{ input: 'a^b$c$d$e$f', expected: 'a^b$c$d$e$f' },
{ input: '^a^b$c$d$e$f$g$', expected: 'a^b$c$d$e$f$g' },
{ input: 'a^b$c$d$e$f$g$', expected: 'a^b$c$d$e$f$g' },
{ input: '^a^b$c$d$e$f$g', expected: 'a^b$c$d$e$f$g' },
{ input: 'a^b$c$d$e$f$g', expected: 'a^b$c$d$e$f$g' },
{ input: '^a^b$c$d$e$f$g$h$', expected: 'a^b$c$d$e$f$g$h' },
{ input: 'a^b$c$d$e$f$g$h$', expected: 'a^b$c$d$e$f$g$h' },
{ input: '^a^b$c$d$e$f$g$h', expected: 'a^b$c$d$e$f$g$h' },
{ input: 'a^b$c$d$e$f$g$h', expected: 'a^b$c$d$e$f$g$h' },
{ input: '^a^b$c$d$e$f$g$h$i$', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: 'a^b$c$d$e$f$g$h$i$', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: '^a^b$c$d$e$f$g$h$i', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: 'a^b$c$d$e$f$g$h$i', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: '^a^b$c$d$e$f$g$h$i$j$', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: 'a^b$c$d$e$f$g$h$i$j$', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: '^a^b$c$d$e$f$g$h$i$j', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: 'a^b$c$d$e$f$g$h$i$j', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: '^a^b$c$d$e$f$g$h$i$j$k$', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: 'a^b$c$d$e$f$g$h$i$j$k$', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: '^a^b$c$d$e$f$g$h$i$j$k', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: 'a^b$c$d$e$f$g$h$i$j$k', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
];
testCases.forEach(({ input, expected }) => {
const result = removeAnchors(input)
})
| ready |
slice | export const removeAnchors = (regexString: string) => {
if (regexString.startsWith('^')) {
regexString = regexString.slice(1)
}
if (regexString.endsWith('$')) {
regexString = regexString.slice(0, -1)
}
return regexString
}
{ input: '^a^b$c$d$', expected: 'a^b$c$d' },
{ input: 'a^b$c$d$', expected: 'a^b$c$d' },
{ input: '^a^b$c$d', expected: 'a^b$c$d' },
{ input: 'a^b$c$d', expected: 'a^b$c$d' },
{ input: '^a^b$c$d$e$', expected: 'a^b$c$d$e' },
{ input: 'a^b$c$d$e$', expected: 'a^b$c$d$e' },
{ input: '^a^b$c$d$e', expected: 'a^b$c$d$e' },
{ input: 'a^b$c$d$e', expected: 'a^b$c$d$e' },
{ input: '^a^b$c$d$e$f$', expected: 'a^b$c$d$e$f' },
{ input: 'a^b$c$d$e$f$', expected: 'a^b$c$d$e$f' },
{ input: '^a^b$c$d$e$f', expected: 'a^b$c$d$e$f' },
{ input: 'a^b$c$d$e$f', expected: 'a^b$c$d$e$f' },
{ input: '^a^b$c$d$e$f$g$', expected: 'a^b$c$d$e$f$g' },
{ input: 'a^b$c$d$e$f$g$', expected: 'a^b$c$d$e$f$g' },
{ input: '^a^b$c$d$e$f$g', expected: 'a^b$c$d$e$f$g' },
{ input: 'a^b$c$d$e$f$g', expected: 'a^b$c$d$e$f$g' },
{ input: '^a^b$c$d$e$f$g$h$', expected: 'a^b$c$d$e$f$g$h' },
{ input: 'a^b$c$d$e$f$g$h$', expected: 'a^b$c$d$e$f$g$h' },
{ input: '^a^b$c$d$e$f$g$h', expected: 'a^b$c$d$e$f$g$h' },
{ input: 'a^b$c$d$e$f$g$h', expected: 'a^b$c$d$e$f$g$h' },
{ input: '^a^b$c$d$e$f$g$h$i$', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: 'a^b$c$d$e$f$g$h$i$', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: '^a^b$c$d$e$f$g$h$i', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: 'a^b$c$d$e$f$g$h$i', expected: 'a^b$c$d$e$f$g$h$i' },
{ input: '^a^b$c$d$e$f$g$h$i$j$', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: 'a^b$c$d$e$f$g$h$i$j$', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: '^a^b$c$d$e$f$g$h$i$j', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: 'a^b$c$d$e$f$g$h$i$j', expected: 'a^b$c$d$e$f$g$h$i$j' },
{ input: '^a^b$c$d$e$f$g$h$i$j$k$', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: 'a^b$c$d$e$f$g$h$i$j$k$', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: '^a^b$c$d$e$f$g$h$i$j$k', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
{ input: 'a^b$c$d$e$f$g$h$i$j$k', expected: 'a^b$c$d$e$f$g$h$i$j$k' },
];
testCases.forEach(({ input, expected }) => {
const result = removeAnchors(input)
})
| ready |