Adding a line of text using "Changes"


I am creating an app that contains some OT books that are polished drafts, for community feedback. I want to make it very clear that the text is in draft state. So, I would like to add the line

\s2 \bd_[Translation is in draft state]\bd*
[Translation is in draft state]

throughout the text.

Notably, on its own line after each instance of

\mt1 book title
\is  introduction section heading 
\c   chapter
\s1  section heading

This is the regex I attempted:
\\(mt1|is|c|s1)( .*\n)
(Look for any instance of those markers with optional text after them)

\1\2\\s2 \\bd_\[Translation is in draft state\]\\bd\*\n
(Replace it with the same, but add a new line that says "[Translation in draft state])

This just garbled the entire book. I tried some variations, such as this simplification:

(\\s1 .*)$
(look for a section header)

\1\ \\bd_\[Traducción estado borrador\]\\bd\*$
(replace it with the same and add the warning on the same line)

But that caused the app to freeze.

Any ideas on how to make such a regex? Thanks!

Also, two related questions:

  • What regex flavor does SAB use? I couldn’t find it noted anywhere.
  • Are the changes made when the app is compiled, or when it is opened on the device?

Possibly relevant:
In this post I read that @GregAshleyCooper observed that SAB has a hard time finding end-of-line characters, at least at the time in 2018.

Key term: regular expressions

Update: I just tried deleting the change and rebuilding, but my app is still freezing, so I must have made some other change that is causing it to freeze…

So obviously you will have to deal with the app freezing issue…

But in my brief testing, this Change works for me for what you are trying to do:
Find: (\\(mt1|is|c|s1) .*\n)
Replace: \1\\s2 \\bd \[Translation is in draft state\]\\bd\*\n

Although if you aren’t using \s2 elsewhere, I would remove the “bold” marking, and just change the style for \s2, as that might be a place for potentially having some parsing problems.

Thanks so much Jeff! Regex always makes my head spin. I see I basically needed to regroup my query.

Good idea on the \s2 formatting too. I decided to leave \bd, just in case we decide to use \s2 in the translation itself at some point.

I did make one change- I had to make a separate change for the introductions, since the new line needed there must be \is2.

These are the changes I ended up with:

Find:    (\\(mt1|is) .*\n)
Replace: \1\\is2 \\bd \[Translation in draft state\]\\bd\*\n

Main body:
Find:    (\\(c|s1) .*\n)
Replace: \1\\s2 \\bd \[Translation in draft state\]\\bd\*\n

Not sure why my app was freezing (infinitly spinning circle upon app load) but removing all my books and readding them seemed to help. It’s working again.

Thanks again.

P.S. I have no idea why the site colored the text red…

It formats according to language.

From Extended Syntax | Markdown Guide

Syntax Highlighting

Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code was written in. To add syntax highlighting, specify a language next to the backticks before the fenced code block.

  "firstName": "John",
  "lastName": "Smith",
  "age": 25

The rendered output looks like this:

  "firstName": "John",
  "lastName": "Smith",
  "age": 25

Great resource! Thanks so much. I figured it was something like this.