Search and replace Regex and AltGr key

Writing a book, Automating Document Production - Discuss your special needs here

Search and replace Regex and AltGr key

Postby G_Ranger » Sun Dec 30, 2018 4:52 pm

Hello to all,
I'd like to be able to use the regex option, in the search and replace box, but regexes often involve the use of special characters accessed with the AltGr keyboard combination. Now, the effect of AltGr, in the search and replace boxes is to select everything in the box. And so if I try and type, say, [(\d)]{1,3} as a way of looking for page numbers between 1 and 999, then I get only as far as [( , the AltGr key selects everything, and so [( is then overwritten by \. I hope this is clear. It's a problem I sometimes have with web forms, too, so maybe this is something to do with my setup. Note finally that I can type my regex in the word processor window, then cut and paste to the search and replace box, as a workaround.
Thanks in advance for any help here.
G. R.
LibreOffice 6.0.6.2 Ubuntu 18.04
G_Ranger
 
Posts: 10
Joined: Thu Jun 29, 2017 4:40 pm

Re: Search and replace Regex and AltGr key

Postby Lupp » Sun Dec 30, 2018 5:15 pm

I have no idea how your problem might be realatde to your settings or to your OS.
Did you already try LibO
Code: Select all   Expand viewCollapse view
Help > Restart in Safe Mode...
to exclude an effect of a corrupted user profile?

Concerning the RegEx:
-1- I don't understand the brackets and the parentheses. \d is a shortcut for the set of decimal digits and doesn't need the brackets.
(If you need [] and/or () as a syntactical markup for page numbers, your expression won't work.)
-2- To get numbers of up to 3 digits exluding parts of longer numbers, you should use:
Code: Select all   Expand viewCollapse view
(?<!\d)\d{1,3}(?!\d)
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2469
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Search and replace Regex and AltGr key

Postby G_Ranger » Sun Dec 30, 2018 6:38 pm

OK, thanks for your answer. It's really the alt gr problem that bothers me!
You're right: I wasn't clear enough in explaining why I was using this RegEx. I had a series of page numbers indicated like this (101) that needed formatting for publication like this (p. 101), and so I was using the brackets as a capturing expression so that I can put "[(\d)]{1,3}" in the search, and "p. $0" in the replace box. Thanks for the advice excluding parts of longer sequences, too. I wouldn't have thought of that!
Safe mode didn't work, unfortunately. Perhaps it's a keyboard setup thing, independently of OpenOffice or LibreOffice...
LibreOffice 6.0.6.2 Ubuntu 18.04
G_Ranger
 
Posts: 10
Joined: Thu Jun 29, 2017 4:40 pm

Re: Search and replace Regex and AltGr key

Postby G_Ranger » Mon Dec 31, 2018 5:45 pm

Hello,
I've found the answer: not (directly) an OpenOffice LibreOffice problem. The problem is due to the keyboard parameter, in the system preferences. It's a bug that affects this parameter when it is set to "ibus".
A little more information: I'm on Ubuntu 18.04 with Unity desktop. I get to the setting by going to "system settings" > "language settings" > "keyboard system" (or something similar -- my setup is in French so the precise terms may be slightly different). I get the choice of three "keyboard system settings": ibus (default), xim or nothing. "ibus" allows the user to type UTF characters directly or to switch from one keyboard to another easily, "nothing" does not allow this, and "xim" was very buggy, for me. So to sum up: either you use the "ibus" default, with more flexible keyboard usage, but a minor bug involving the AltGr key, or you don't need the extra keyboards, UTF, etc. and you switch to "nothing".
G. R.
LibreOffice 6.0.6.2 Ubuntu 18.04
G_Ranger
 
Posts: 10
Joined: Thu Jun 29, 2017 4:40 pm

Re: Search and replace Regex and AltGr key

Postby Lupp » Mon Dec 31, 2018 6:33 pm

Glad to hear you found the solution concerningf AltGr.

Concerning the RegEx;
To get the found number as a group you can reference, you would need the (round) parentheses capturing it. If you work with the square brackets for a character set and a range quantifier like {1,3} you need that all inside the grouping parentheses. The parentheses surrounding the match being used as a markup for page numbers may be matched as zero-length assertions of lookbehind and lookahead type respectively. You might use
Code: Select all   Expand viewCollapse view
(?<=\()(\d{1,3})(?=\))
as the RegEx to find, and
Code: Select all   Expand viewCollapse view
p. $1
as the expression to replace with.


Sorry. I forgot about the bug https://bugs.documentfoundation.org/sho ... ?id=111646 I had reported myself to the LibO bugtracker. Obviously AOO is also afflicted.
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2469
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Search and replace Regex and AltGr key

Postby keme » Tue Jan 01, 2019 1:40 pm

Potential workarounds:
  • Type the backslash first, then build the rest of the search term around it.
  • Type the search expression elsewhere or keep a set of "AltGr-characters" you commonly use in a text file, and use copy/paste.
  • Type in the backslash as a unicode "code point": ctrl+shift+U, 005c, space
  • If fast keyboard switching works without side effects, find a keyboard setup where the backslash does not require a modifier key. Switch back and forth as required.
If none of those options work, the hassle of changing back and forth between keyboard interfaces is probably the best "workaround".
User avatar
keme
Volunteer
 
Posts: 3156
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Search and replace Regex and AltGr key

Postby RobertClive » Mon Feb 25, 2019 1:14 pm

This doesn't answer your direct question but for future use, research changing your keyboard design. I usually use English (International AltGr dead keys) in Linux (Ubuntu). An é is simply a matter of holding down the right Alt-key and pressing e. I think the design name for the equivalent Windows keyboard is similar . The keyboard appears to offer symbols to the key European vocabulary. Alternatively, assuming you are using a regular QWERTY keyboard (UK/US/etc.) , perhaps switch to some keyboard that is French-Canadian? The majority of the keyboard design is the same as an English language QWERTY in which punctuation marks appear with some differences. This keyboard provides a committed É & é secret where the? Looks on the QWERTY keyboard. There's hardly any difference in utilizing the 2 layouts if you're typing text that is straight.
OpenOffice 4.1.4 Windows 10
RobertClive
 
Posts: 2
Joined: Mon Feb 25, 2019 12:59 pm

Re: Search and replace Regex and AltGr key

Postby jrkrideau » Tue Feb 26, 2019 9:00 pm

And a Ubuntu user can install On Board to see what the keyboard layout is. If it is not already installed, as simple "sudo apt install onboard" should de the trick.
OpenOffice 4.1.6; Ubuntu 18.04
jrkrideau
Volunteer
 
Posts: 3684
Joined: Sun Dec 30, 2007 10:00 pm
Location: Kingston Ontario Canada


Return to Advanced Uses

Who is online

Users browsing this forum: No registered users and 0 guests