0

On notion i am trying to create a formula. that uses replace inside of a replaceall with a regex im having an issue on putting the prop value inside the double quotes in the replace.

The code in working state;

replaceAll(replace(prop("all chapter numbers"), "(?:[^,]*,){2}", ""), ",.*", "");

What i am trying to accomplish to


replaceAll(replace(prop("all chapter numbers"), "/(?:[^,]*,){prop("total checked chapter")}", ""), ",.*", "")

I have tried to use the template literal instead of the simple quotation. Which resulted on notion formula not recognizing the code and simply telling me " needed.

Because i had no clue about JavaScript and template literal i have did some research and try to replicate from the examples.

Firstly because notion reaplace formula looking much diffrent that what i have seen on javascript sites i tried to do it on one replace then add the other one afterwards.

notion replace

replace("Visit Microsoft","Microsoft","W3Schools");

notion replaceAll

javascript examples i have seen

let text = "Visit Microsoft!";
let result = text.replace("Microsoft", "W3Schools");

implementing onto my issue

Try1:

replace(prop("all chapter numbers")),`(?:[^,]*,)${prop("total checked chapter")}`, ``)

Output syntax error

try1

replace(prop("all chapter numbers"),`(?:[^,]*,){${total checked chapter}}`,"" )

try1.1

I have checked this question

That i have to use new regExp but i got no info on the web how to use a newregex on the syntax of notion replace formula.

from the w3 school example i tried to put my prop/string value with ${}

replace(prop("all chapter numbers"),"(?:[^,]*,){${total checked chapter}}","" )

but in this one it did not saw my value and counted as 0 so the result

if i try to change the "" double quotes like this

replace(prop("all chapter numbers"),`(?:[^,]*,){${total checked chapter}}`,"" )

it will give me the same syntax issue on the other examples like this

i even tried another solution i have seen that uses '\b{replacethis}\b'

replace(prop("all chapter numbers"),`\\b${total checked chapters}\\b` , "")

results regex results

shac
  • 9
  • 3
  • Use template literal. Then `${prop(......)}` – trincot Feb 01 '23 at 18:30
  • if i add the template with ${prop()} it still doesn't fix the issue and gives the same errors because of quotation marks. replaceAll(replace(prop("all chapter numbers"),"(?:[^,]*,){${prop("total checked chapter")}}", ""), ",.*", "") Error! == ) expected (char 89) – shac Feb 01 '23 at 19:13
  • That's not a template literal. Please look up the documentation on that subject. – trincot Feb 01 '23 at 20:13
  • I have checked the documentations: "Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, ..." The issue is... in any part of this formula i can't use the backtick.... If i try to change it or add it it will always give me a Syntax error related to it.. On notions formulas for me to use replace like replaceAll(text, text, text) i have to use replace("text","text","text") syntax and i can't interchange any of them with this . I am pretty new on this so apologies if i didn't understand something correctly. – shac Feb 01 '23 at 20:40
  • anywhere where you can use string literals you can use template literals. They are just syntax for string literals with interpolation possibilities. – trincot Feb 01 '23 at 20:43
  • I understand that... But the issue still persists if i use a template literal instead of string literal it will just print out an error saying. " excepted . and not even on the part i used a regex. It will give me the same issue and error output on any place where i try to use it. – shac Feb 01 '23 at 21:28
  • I don't know which code you are talking about as there are no template literals in your question. – trincot Feb 01 '23 at 22:23
  • I updated the question and tried to show as much trial and erorr with the thought process behind it . could you please check what am i not doing right or not seeing it clearly @trincot – shac Feb 03 '23 at 14:34
  • Can you edit your question and include (as typed text, not as image) sample input/output? Like: what is the value of `prop("total checked chapter")` and of `prop("all chapter numbers")` and what you expect as result after having called the `replace` function for these values? – trincot Feb 03 '23 at 14:48

0 Answers0