Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: Regex question  (Read 1536 times)

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Regex question
« on: June 15, 2021, 04:16:34 PM »

I am using a regular expression replace function (in the iPadOS "Shortcuts" language). The regex is
    ^(\d+)$
and the replace string is
    $10
Now this is supposed to append a zero on to the end of decimal numbers, by matching group one. It is not intended to mean match group ten !

This set me thinking about the more general problem. From what I read the situation seems to be a right mess with some implementations of regex engines allowing more than just the nine groups $1-$9 and others not, and some allowing alternative syntax in the replace string, like "${1}" or some such. Is there any other way around this, the situation where a digit is supposed to follow a group number ? Say something like "$1\0" for ‘literal 0’ or some kind of ‘concatenation operator’ like when "##" is used to prevent adjacent items from being seen as one single token. Or some alternative group replacement symbol?

I suppose in that one case an alternative would be to use a lookahead match in the match string instead of copying a group and putting it back in in the replace string.
Logged
 

anything