[Solved] Regular expression in search

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
emf
Posts: 79
Joined: Tue Aug 12, 2008 8:44 am
Location: New York

[Solved] Regular expression in search

Post by emf »

I would like to change all
##,
to
*##,

where # is a digit, an * just a symbol (it could be something else).
Can I do this in 1 search and replace all using regular expressions?
Last edited by Hagar Delest on Mon Jul 23, 2018 10:17 pm, edited 1 time in total.
Reason: tagged [Solved].
OO 4.1.6 in 64 bit Windows 10
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: regular expression in search

Post by RoryOF »

AltSearch from the extensions repository should do this for you.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Regular expression in search

Post by Lupp »

Why did you post this in the 'Macros' branch?

In a RegEx a single digit is represented by "[0-9]", two subsequent digits by "[0-9]{2}" To make the finding available in the ReplaceWith you can use the RegEx "([0-9]{2})" and reference the found string by "$1". I use 'Prefix' now for what you represented by an asterisk.
Search for : ([0-9]{2})
Replace with: Prefix$1
With Prefix = § applied with 'Replace All' to foo1978bar this would result in foo§19§78bar.
If this is not what you want, please explain your intentions more precisely.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Regular expression in search

Post by John_Ha »

See [Tutorial] How to record a macro (and Regular Expressions)

Showing that a problem has been solved helps others searching so, if your problem is now solved, please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
emf
Posts: 79
Joined: Tue Aug 12, 2008 8:44 am
Location: New York

Re: Regular expression in search

Post by emf »

Lupp from Munchen, I posted here because the issue was part of a macro, and I thought tjat I'd need additional help. However your help solved the problem. Thanks

Eustace from New York
OO 4.1.6 in 64 bit Windows 10
Post Reply