Search Postgresql Archives

Re: back references using regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Peter <survivedsushi@xxxxxxxxx> writes:

> One other thing, when I wrote back I actually used
> 34.31.29.20 (random), not 12.00.00.34 like i showed in
> the example, which is why i said it didn't work on
> digits.
>
> SELECT substring('34.31.29.20' FROM $$((\w+)\.\2)$$);
>   substring 
>  -----------
>   
>  (1 row)
>
> little did i know writing it with 12.00.00.34 would
> return 00.00... so yes, that did suprise me.
> Apparently only using the identical values returns a
> value. so it's saying x+ one more of the same value
> separated by a period... where shouldn't it be any
> "letter, number or underscore" followed by any
> "letter, number or underscore"?

Backreferences match the exact string matched by the corresponding set
of parentheses.  It's not the equivalent of substituting in the
parenthesized part of the regex and testing that for a match.  The
behavior above is as expected.  If you want it as "any followed by
any" you shold write the regex as '((\w+)\.(\w+))' -- then the two
parts can differ.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux