Ask Your Question
0

Writer: Find and Replace style between curly brackets

asked 2017-08-21 19:09:04 +0200

dgsarnow gravatar image

I have a document that several instances of terms surrounded by curly braces - {Example}. The number of characters between the braces varies. I am trying to use Find and Replace to change the style of the font for everything inside of the braces including the braces.

I am using the search term \{.*\} with Regular Expressions checked. it seems to work in most cases, but there are several instances where it will find one of the sets of the brackets and also include all the text between that instance and the next instance of brackets. Here is an example:

{IndexKey} and {EntryKey}

In the case above, rather than find just "{IndexKey}" Find and Replace is highlighting "{IndexKey} and {EntryKey}".

Is this a bug or am I missing something in my expression?

edit retag flag offensive close merge delete

Comments

It's not a bug but the result of the 'greedy' behavior of the search routine - that is it will find the longest string matching the expression. While intentional, I don't really know why the developers opted for this behavior. There may be occasions where it comes in handy, but in most cases, like this, it's a nuisance.

floris v gravatar imagefloris v ( 2017-08-21 21:48:42 +0200 )edit

@floris v: if you look at the full list of regular expressions (mentioned in the comment to @Grantler's answer), you'll see the operator ? that defines the non-greedy matching ("as few as possible"). That is the way ICU does things.

Mike Kaganski gravatar imageMike Kaganski ( 2017-08-22 14:39:13 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2017-08-21 20:55:21 +0200

Grantler gravatar image

updated 2017-08-21 21:20:56 +0200

Try this:

\{\w*\}

Note: The SEARCH FOR .* includes each "character", even if it is a bracket.
The \w* only includes "word character", i.e. letters and underscore
→ a little bit more than [A-Za-z0-9].
If a space is included use
\{[a-zA-Z0-9 ]*\}
Find the difference of the used expressions on Wikipedia, regular expressions.

So, you haven't found a bug.

Unfortunately (?) the LO help system does only offer a limited range of RegEx so that one sometimes has to search on the internet for more possible expressions.

Cheers

edit flag offensive delete link more

Comments

The List of Regular Expressions in LO help links to two wiki articles (for Writer and Calc), and those in turn link to full list of regular expressions.

Mike Kaganski gravatar imageMike Kaganski ( 2017-08-21 21:02:51 +0200 )edit
0

answered 2017-08-22 13:52:25 +0200

ajlittoz gravatar image

It looks like {something} has a specific meaning in your document. Consequently, you should mark it up with a character style. Unfortunately, you cannot use advanced options of Edit>Search & Replace to set a character style to the found sequence. However, since character style usage gives you a tremendous editing power on your text, you should do it.

  1. Create a character style and name it Curly for example. Set the font and other attributes to your taste. Do not set font size, so that it inherits the font size of the paragraph it is in.
  2. Search for the next curly sequence with the regular expression.
  3. While the found sequence is still selected, reset all attributes to their default values with Format>Clear direct formatting or Ctrl+M, then apply Curly character style.
  4. Do 2 & 3 again for the other curly sequences

Now, if you want to change the appearance of your curly sequences in a single shot, modify the Curly character style and all sequences will immediately reflect the new style.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-21 19:09:04 +0200

Seen: 631 times

Last updated: Aug 22 '17