Looking for help with a query similar to the one referenced here.
I am new to TypeScript and front end development. Currently using an Angular form to collect user input, which may contain regex.
For example:
The input from the form, stored in this.expressions, can consist of multiple expressions separated by a new line character.
this.rewrite_object = []
this.expressions = "s|.*|{{ date | replace('-', '') }}\"/apps/data/{{ date | replace('-', '/') }}"
this.rewrite_array = this.expressions.split('\n')
console.log("******************Print after split******************")
console.log(this.rewrite_array)
if (this.rewrite_array.length > 0) {
for(var i = 0;i<this.rewrite_array.length;i++) {
if (this.rewrite_array[i]) {
console.log("******************Print before adding to array******************")
console.log(this.rewrite_array[i])
this.rewrite_object.push({ "expression": this.rewrite_array[i] });
console.log("******************Print rewrite object******************")
console.log(this.rewrite_object)
}
}
}
The output shows that the escape character is disappearing.
******************Print after split******************
[
`s|.*|{{ date | replace('-', '') }}"/apps/data/{{ date | replace('-', '/') }}`
]
******************Print before adding to array******************
s|.*|{{ date | replace('-', '') }}"/apps/data/{{ date | replace('-', '/') }}
******************Print rewrite object******************
[
{
expression: `s|.*|{{ date | replace('-', '') }}"/apps/data/{{ date | replace('-', '/') }}`
}
]
I considered using \ to escape the escape character itself, but encountered errors during compilation.
test.ts:2:70 - error TS1136: Property assignment expected.
2 this.expressions = "s|.*|{{ date | replace('-', '') }}\\"/apps/data/{{ date | replace('-', '/') }}"
~
test.ts:2:98 - error TS1128: Declaration or statement expected.
2 this.expressions = "s|.*|{{ date | replace('-', '') }}\\"/apps/data/{{ date | replace('-', '/') }}"
~
test.ts:2:100 - error TS1002: Unterminated string literal.
2 this.expressions = "s|.*|{{ date | replace('-', '') }}\\"/apps/data/{{ date | replace('-', '/') }}"
Found 3 errors.
I need to find a way for the quotation marks to work as intended with TypeScript, as I have to save this information in a database after collecting it from customers.