How to extract a part of string from fields in QGIS field calculator?
Clash 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:
Does anyone know any way to modify/accommodate the expression?
qgis attribute-table expression string function
add a comment |Â
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:
Does anyone know any way to modify/accommodate the expression?
qgis attribute-table expression string function
Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run asubstr
, since your path and length of expression is always the same.
– Erik
Sep 5 at 7:54
add a comment |Â
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:
Does anyone know any way to modify/accommodate the expression?
qgis attribute-table expression string function
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:
Does anyone know any way to modify/accommodate the expression?
qgis attribute-table expression string function
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 asubstr
, since your path and length of expression is always the same.
– Erik
Sep 5 at 7:54
add a comment |Â
Does it work when you replace the * with a +? I don't really get the syntax either. Alternatively you could run asubstr
, 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
add a comment |Â
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)
In the above example I used Path
instead of Location
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
add a comment |Â
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:
add a comment |Â
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)
In the above example I used Path
instead of Location
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
add a comment |Â
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)
In the above example I used Path
instead of Location
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
add a comment |Â
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)
In the above example I used Path
instead of Location
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)
In the above example I used Path
instead of Location
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
add a comment |Â
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
add a comment |Â
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:
add a comment |Â
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:
add a comment |Â
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:
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:
answered Sep 5 at 13:39
asongtoruin
1706
1706
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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