Regular expression text replacement nonfunctional

Being back in here for something else today, occurred that @AmberV 's request to make identifiable bugs evident on the new forum should get another.

Regular expressions are very useful indeed for those unusual searches and replaces that can very much streamline getting some text in shape.

The problem I’ve most noticed on Scrivener iOS is that replacement using character codes doesn’t function – nothing happens.

An evident example is with trying to put in additional paragraph separators (\n) when the paragraphs are jammed together, possibly from being copied that way from another source.

You should be able to select on RE ‘\n’, and replace it with ‘\n\n’, each in its blank on Scrivener, naturally without the quotes. Using Replace All should clean up any length of text – voila.

What actually happens is that the \n newlines that did exist will be replaced with nothing, so that you get the paragraphs all jammed together and must hope for an Undo.

This is the big one, probably, but if it’s fixed, that probably means the RE library is now called correctly, and so all REs in the fashion of Apple’s version should work.

It would be well for completeness, though, to have a few interesting cases to test this success – for example that capture groups and their ability to copy text into a new place in a replace result also works. This would be very useful for reformatting labeled items, for example.

Good fortune!

It seems to me the regex engine is working generally, in that if I search for example (\w+)\.$ and replace with $1----, then every sentence at the end of a paragraph gets four hyphens at the end instead of a period.

I believe this issue with not recognising escaped whitespace characters in the replacement field is common to Apple’s regex implementations. The same issue exists on the Mac as well—you have to insert physical whitespace characters into the replacement field rather than using \t or whatever.

The problem with iOS is that it doesn’t seem to care for literal whitespace characters in search fields. You can’t copy and paste a break or tab into the field, it just turns into a space. This appears to be a common problem across different apps.

Ioa, think you’re right about this, at the least as far as easy discovery of workarounds goes.

In fact, I couldn’t really find the aspects documented, though believe I’ve heard of them before, now memory says, and that solutions were originally supposed to be provided by graphical means. That would be the nature of Steve Jobs’ original world…

Here’s an easy solution I found, given especially that you’ve shown the awareness and testing for the more complex replacement abilities of Regexhave been there; thus we can trust the basic framework is fully there.

On any iPad, one can have the Pages app for free from Apple, and it turns out that it does recognize \n both in Find and Replace. And it does have Replace All even if it seems invisible – you just lean on the Replace button an extra moment, and that useful button will show.

So, a quick copy-paste of original text, running for example Find \n with Replace \n\n and engaging Replace All will get spaced paragraphs, which then can be copy-pasted back into Scrivener.

This makes an easy way for anyone to rapidly fix this kind of formatting, would hope.

And if there’s the moment to look into it while makeing other updatss sometime, it occurs to me that it could likely be easy to provide a pre-scan effect in the Scrivener code, to string replace the Replace \n elements with the internal iPadOS newline token, just before running its actual regex. The kind of bodge that simply makes what’s visible smooth, if it would work…one may have a favor for :slight_smile:

Thank s for looking at this, and the careful answer, always appreciated. If we can’t do anything, then the Pages solution is actually pretty good, and in fact makes it unnecessary to know about technical matters at all…