using \t in regular expression replace

Hi all,

I was trying to use \t to replace e.g a paragraph ending with a tab.
So find $ replace with \t

That does not work.
Nor in combination with ^ or \n (one has to try something :wink: )

I can replace e.a. an character with a tab though.

This is the same in 3.3.4, 3.4.6, 3.5.7, 3.6.2.2

(Testing on Ubuntu/Linux).

So prolly I try something that can't be done (not directly anyway) or something that should be done in a different way?

thanks for replies,
Cheers,

Hi :slight_smile:
Is \t reserved for something in LO or in your OS?

Can you replace $ with zzzz?  If that works can you replace zzzz with \t?  Also can you try doing those replacements in a normal text-editor to try to pin it down to either the OS or LO?

Regards from
Tom :slight_smile:

At first I did not understand what you meant since paragraphs always end with paragraph breaks. Well they do, but that does not mean there has to be any punctuation at the end of the paragraph.
       Here is what I was able to do: In the search box, I entered .$ (period followed by the dollar sign). This searches paragraphs that end with a period. In the Replace box, I entered \t. Clicking the Find and then Replace buttons changed the period to a tab. This is for 3.6.2.2.
      I think a possible problem is that you did not enter the ending punctuation for a paragraph. Probably this will only search for one type of punctuation mark at a time.
      HTH

--Dan

I was trying to use \t to replace e.g a paragraph ending with a tab. So find $ replace with \t That does not work.

At first I did not understand what you meant since paragraphs always end with paragraph breaks.

The questioner presumably wants to merge existing paragraphs: removing paragraph breaks and replacing them by tab characters.

Here is what I was able to do: In the search box, I entered .$ (period followed by the dollar sign). This searches paragraphs that end with a period.

Sorry, but that's not so. If "Regular expressions" is not ticked, then .$ matches exactly that: a dot followed by a dollar sign - nothing about paragraph breaks. If "Regular expressions" is ticked, then .$ matches any single character but only if it occurs at the end of a paragraph. But note in this latter case that the expression matches only that single character, without including the paragraph break itself. So any replacement replaces the single character but leaves the paragraph break as it was.

The $ sign anchors any search to the end of a paragraph, but does not match the paragraph break itself, which - in the view of LibreOffice's regular expressions - does not exist as a separate entity. There is no simple way to match and replace paragraph breaks, I think. (You can match and replace Shift+Enter line breaks - using \n.)

I trust this helps.

Brian Barker

Weirdly that's true: if you search for $ on its own, you can replace the paragraph breaks with something else. The problem is then only that "\t" in the "Replace with" box is interpreted as text instead of a regular expression. (Surely that's wrong?) But you've found the solution. (I spotted this part but didn't latch on to its significance.)

With "Regular expressions" ticked, first search for $ and replace with a character or string that does not occur in your document - perhaps a hash mark? Then repeat the search (still with "Regular expressions" ticked), this time searching for # and replacing with \t.

Sorry for previous distraction. I trust this helps.

Brian Barker

I guess I could send a bug report to this list then… I seem to never
get used to the new behaviour of it (that I need to click ”Reply to
all” and then move around the addresses – I use Gmail from its web
interface and there is no ”Reply to list” button). I'm subscribed to
quite a few lists and this is the only one (or maybe there is one more
that I never write to anyway) that behaves this way. I have sent quite
a few messages privately by mistake since the change, so I guess I'll
never learn…

Before doing anything else now, I will file a bug report to Gmail,
telling them that they'd better add a Reply to list-button…

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

Hi all,

Brian Barker wrote (07-10-12 16:01)

The problem I encountered was that the paragraph breaks was replaced
with the characters "\t", not the [tab] (tab) character, no matter if
"Regular expressions" were ticked or not. I got the same result when
trying to replace with \x09: The paragraph breaks were replaced with
the characters "\x09", not the [tab] character.

But maybe that's only me, I am not the OP, so feel free to ignore this.

Weirdly that's true: if you search for $ on its own, you can replace the
paragraph breaks with something else. The problem is then only that
"\t" in the "Replace with" box is interpreted as text instead of a
regular expression. (Surely that's wrong?) But you've found the
solution. (I spotted this part but didn't latch on to its significance.)

AH yes, that was the only thing that I did not write in my original post. Sorry for that.

With "Regular expressions" ticked, first search for $ and replace with a
character or string that does not occur in your document - perhaps a
hash mark? Then repeat the search (still with "Regular expressions"
ticked), this time searching for # and replacing with \t.

Of course I used this workaround.
But I wondered if I did something wrong, or missed some special trick to replace $ with a <tab> in one run.

Sorry for previous distraction. I trust this helps.

No problem of course. Thanks to you & all for the replies.

I think this is worth a bug report/request for enhancement.

Cheers,

http://extensions.libreoffice.org/extension-center/alternative-dialog-find-replace-for-writer

Am 08.10.2012 09:03, Cor Nouws wrote:

Of course I used this workaround.
But I wondered if I did something wrong, or missed some special trick to
replace $ with a <tab> in one run.

The $ does not match any character. It matches a position. You may think
of the position where the bar cursor blinks when you navigate behind
last character of a paragraph. Likewise, the ^ represents the position
before the first character of a paragraph. The paragraph break between
the 2 positions is unmatchable.
\< and \> represent the positions in front of the first or behind the
last character of a word respectively.

\n in the regex search field matches a line break (Shift+Enter in
Writer, Ctrl+Enter in Calc). In the replace field the \n represents a
paragraph break. It is a long standing and highly irritating issue that
replacing \n with \n replaces line breaks with paragraph breaks.

That's what I understood too. But, contrary to this, searching for $ *does* match the paragraph break (whether or not it is supposed to). Strangely, though, \t in the "Replace with" field is then not interpreted properly. Hence the need for the workaround.

Brian Barker