I have a string str defined as :
const str = `
@get body {
Anything here.....
Any no. of lines
Or, empty lines as above
}
`
I made a function get() which, by name gets the element, the @get is marking , and yes the content between the { & }. It can be used something like this :
console.log(get(str))
// body
/*
Anything here.....
Any no. of lines
Or, empty lines as above
*/
So, the source of my function ( I don't have much experience to use match(), so I usually use replace() for getting the value as well as replacing with anything if and only if I require, so please feel free to edit my code ) :
const get = (val) => {
val.replace(/@get(.*?)\{([\S\s]*?)\}/gm, (_, a, b) => {
console.log(a)
console.log(b)
}
}
So, now my question is what if I remove the brackets i.e { & } ? Assumed syntax :
const str = `
@get body
Anything here.....
Any no. of lines
Or, empty lines as above
Don't catch me !
`
console.log(get(str))
Now, the output remains same. How how can I make my get() function space sensitive. You can see that the sentence "Don't catch me !", have the same no. of spaces in front of it as of the @get, therefore it is parsed as an external content and is not stated as the content of the @get body block, hence not displayed. So, I am thinking how to do it ? Is it possible in javascript ?