How to extract a part of string from fields in QGIS field calculator?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression:



regexp_substr( "Text", '/(\d*)_' )



(based on this working example: Obtaining specific part of string from field in QGIS attribute table?)



However, the expression does not give the desired result in my case:



enter image description here
Does anyone know any way to modify/accommodate the expression?







share|improve this question






















  • Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
    – Erik
    Sep 5 at 7:54
















up vote
3
down vote

favorite












I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression:



regexp_substr( "Text", '/(\d*)_' )



(based on this working example: Obtaining specific part of string from field in QGIS attribute table?)



However, the expression does not give the desired result in my case:



enter image description here
Does anyone know any way to modify/accommodate the expression?







share|improve this question






















  • Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
    – Erik
    Sep 5 at 7:54












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression:



regexp_substr( "Text", '/(\d*)_' )



(based on this working example: Obtaining specific part of string from field in QGIS attribute table?)



However, the expression does not give the desired result in my case:



enter image description here
Does anyone know any way to modify/accommodate the expression?







share|improve this question














I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression:



regexp_substr( "Text", '/(\d*)_' )



(based on this working example: Obtaining specific part of string from field in QGIS attribute table?)



However, the expression does not give the desired result in my case:



enter image description here
Does anyone know any way to modify/accommodate the expression?









share|improve this question













share|improve this question




share|improve this question








edited Sep 6 at 22:40









PolyGeo♦

51.8k1777231




51.8k1777231










asked Sep 5 at 7:40









abrobia

224




224











  • Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
    – Erik
    Sep 5 at 7:54
















  • Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
    – Erik
    Sep 5 at 7:54















Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
– Erik
Sep 5 at 7:54




Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run a substr, since your path and length of expression is always the same.
– Erik
Sep 5 at 7:54










2 Answers
2






active

oldest

votes

















up vote
9
down vote



accepted










Since the number of charaters are same, you can use substr() function on a new field as in the following expression:



substr( "Location" ,17,6)


enter image description here



In the above example I used Path instead of Location






share|improve this answer






















  • Thx a lot for answering with this example! it works perfectly :) Thxthxthx
    – abrobia
    Sep 5 at 8:19






  • 2




    Please accept the answer if it helped you solve your problem.
    – ahmadhanb
    Sep 5 at 8:46

















up vote
4
down vote













A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:



regexp_substr( "location", '/w(\d*)_' )


but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:



regexp_substr( "location", '(\d*)_' )


As can be seen here:



enter image description here






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f294986%2fhow-to-extract-a-part-of-string-from-fields-in-qgis-field-calculator%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    9
    down vote



    accepted










    Since the number of charaters are same, you can use substr() function on a new field as in the following expression:



    substr( "Location" ,17,6)


    enter image description here



    In the above example I used Path instead of Location






    share|improve this answer






















    • Thx a lot for answering with this example! it works perfectly :) Thxthxthx
      – abrobia
      Sep 5 at 8:19






    • 2




      Please accept the answer if it helped you solve your problem.
      – ahmadhanb
      Sep 5 at 8:46














    up vote
    9
    down vote



    accepted










    Since the number of charaters are same, you can use substr() function on a new field as in the following expression:



    substr( "Location" ,17,6)


    enter image description here



    In the above example I used Path instead of Location






    share|improve this answer






















    • Thx a lot for answering with this example! it works perfectly :) Thxthxthx
      – abrobia
      Sep 5 at 8:19






    • 2




      Please accept the answer if it helped you solve your problem.
      – ahmadhanb
      Sep 5 at 8:46












    up vote
    9
    down vote



    accepted







    up vote
    9
    down vote



    accepted






    Since the number of charaters are same, you can use substr() function on a new field as in the following expression:



    substr( "Location" ,17,6)


    enter image description here



    In the above example I used Path instead of Location






    share|improve this answer














    Since the number of charaters are same, you can use substr() function on a new field as in the following expression:



    substr( "Location" ,17,6)


    enter image description here



    In the above example I used Path instead of Location







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 6 at 0:43

























    answered Sep 5 at 7:59









    ahmadhanb

    18.8k21543




    18.8k21543











    • Thx a lot for answering with this example! it works perfectly :) Thxthxthx
      – abrobia
      Sep 5 at 8:19






    • 2




      Please accept the answer if it helped you solve your problem.
      – ahmadhanb
      Sep 5 at 8:46
















    • Thx a lot for answering with this example! it works perfectly :) Thxthxthx
      – abrobia
      Sep 5 at 8:19






    • 2




      Please accept the answer if it helped you solve your problem.
      – ahmadhanb
      Sep 5 at 8:46















    Thx a lot for answering with this example! it works perfectly :) Thxthxthx
    – abrobia
    Sep 5 at 8:19




    Thx a lot for answering with this example! it works perfectly :) Thxthxthx
    – abrobia
    Sep 5 at 8:19




    2




    2




    Please accept the answer if it helped you solve your problem.
    – ahmadhanb
    Sep 5 at 8:46




    Please accept the answer if it helped you solve your problem.
    – ahmadhanb
    Sep 5 at 8:46












    up vote
    4
    down vote













    A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:



    regexp_substr( "location", '/w(\d*)_' )


    but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:



    regexp_substr( "location", '(\d*)_' )


    As can be seen here:



    enter image description here






    share|improve this answer
























      up vote
      4
      down vote













      A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:



      regexp_substr( "location", '/w(\d*)_' )


      but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:



      regexp_substr( "location", '(\d*)_' )


      As can be seen here:



      enter image description here






      share|improve this answer






















        up vote
        4
        down vote










        up vote
        4
        down vote









        A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:



        regexp_substr( "location", '/w(\d*)_' )


        but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:



        regexp_substr( "location", '(\d*)_' )


        As can be seen here:



        enter image description here






        share|improve this answer












        A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:



        regexp_substr( "location", '/w(\d*)_' )


        but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:



        regexp_substr( "location", '(\d*)_' )


        As can be seen here:



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 5 at 13:39









        asongtoruin

        1706




        1706



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f294986%2fhow-to-extract-a-part-of-string-from-fields-in-qgis-field-calculator%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery