Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
findrx, back referencing, and variable assignment
#1
is there a way to assign the values of the back references to variables in one fell swoop?

eg
Code:
Copy      Help
str a b c
c="quickmacros.com"
findrx(c "(q.*s)\.(\D{2,3})")
a=$1;;which would be "quickmacros"
b=$2 ;;which would be "com"
An old blog on QM coding and automation.

The Macro Hook
#2
But there are no bakreferences. Do you mean subpaterns? Anyway, a backreference match is exactly the same as the subpatern that it references.

Code:
Copy      Help
str c; ARRAY(str) a
c="computers.com"
findrx(c "(c.*s)\.(\D{2,3})" 0 0 a) ;;no backreferences
;findrx(c "(c\D{2}).*?\.(\1)" 0 0 a) ;;backreference \1

out a[0]
out a[1]
out a[2] ;;if it is backreference, it is equal to a[1]

If there are > 1 subpaterns, you need ARRAY. If 1, str.
#3
the array setup will work fine.

i guess im not understanding Friedl's section on backreferenceing. i thought the parenthetical phrases were the backreferencing and the "(\1)" was just a way to tell the code which backreference to, for example, pass to a variable.

is that not correct?
An old blog on QM coding and automation.

The Macro Hook
#4
We can speak about back references only when using a \number. Phrases in () are called subpatern or capturing subpatern or subexpression.

Back references are particularly useful when removing html or similar tags:

<tag ...>text</tag>

<(\w+).*?>(.*?)</\1>


Forum Jump:


Users browsing this thread: 1 Guest(s)