[Qgis-user] Field calculator regexp_substr.

Fernando M. Roxo da Motta petro at roxo.org
Thu Nov 5 14:27:33 PST 2015


On Thu, 5 Nov 2015 20:14:22 -0200, "Fernando M. Roxo da Motta"
<petro at roxo.org> wrote:

  Sorry to answer to myself,


  I continued to try and (almost accidentally) I found that I need to
use the "memory" (the parenthesis) to define what is the desired
substring:

   to_int( regexp_substr( "Label", '([0-9]{1,})'))

  I found it when an expression like:

   
  regexp_substr( 'abd123de45', '.*([0-9]{1,}).*')

Returned the expected 123.  when I removed the ".*" and the "memory" it
returned nothing.


  Sorry to bother.


  Thanks anyway.


> 
> 
>   Hi all,
> 
> 
>   I have a shapefile with a string field (Label) with a content like
> "Line '15'", a text string (without the double quotes).  I want to
> create a new numeric field containing the value in the string field.
> 
>   I was able to create it using the function:
> 
>   to_int( regexp_replace( "Label", '.*([0-9]{1,}).*', '\\1''))
> 
>   I noticed that there is a function "regexp_substr", if I understood
> correctly, I should be able to use this just specifying the regex of
> the desired substring.  I hoped to be able to use:
> 
>    to_int( regexp_substr( "Label", '[0-9]{1,}'))
> 
> The return are just empty strings.    Am I missing something?
> 
>   BTW, I am using Qgis 2.12.0-Lyon on Xubuntu 14.04 64 bits.
> 
> 
>   Best regards.
> 
> 
> 
>   Roxo
> 








  Roxo

-- 
---------------- Non luctari, ludare -------------------+ WYSIWYG
Fernando M. Roxo da Motta <petro at roxo.org>              | Editor?
Except where explicitly stated I speak on my own behalf.|  VI !!
      ( Usuário Linux registrado #39505 )               | I see text,
------------ Quis custodiet ipsos custodes?-------------+ I get text!
 



More information about the Qgis-user mailing list