You could try something like this:
create table test (field1 varchar(100));
select * from test;
+------------------------------------+
| field1 |
+------------------------------------+
| sometext.step1 |
| sometext.step1.cards.choice_step_1 |
| sometext.step1.cards.choice_step_2 |
| sometext.step1.desire |
| sometext.step2 |
| sometext.step2.cards.choice_step_1 |
| sometext.step2.cards.choice_step_2 |
| sometext.step2.desire |
| step1 |
+------------------------------------+
Query:
select
field1,
-- find position of step
position('step' in field1) as step,
-- find position of dot AFTER step is found
position('.' in
substr(field1, position('step' in field1), length(field1)))
+ position('step' in field1) as dot,
-- if position of 'step' --and-- position of 'step' + position of 'dot' is 1
-- that means: step is at position 1 and dot is not found, display field as is
-- if position of 'step' --and-- position of 'step' + position of 'dot' are equal
-- that means: dot is not found. Grab everything from step onwards
-- if position of 'step' --and-- position of 'step' + position of 'dot' are **NOT** equal
-- grab everything from where step was found thruogh just before dot was found
case
when position('step' in field1) = 1
and
position('.' in substr(field1, position('step' in field1), length(field1)))
+ position('step' in field1) = 1
then
field1
when position('step' in field1) =
position('.' in substr(field1, position('step' in field1), length(field1)))
+ position('step' in field1)
then
substr(field1, position('step' in field1), length(field1))
else
substr(field1,
position('step' in field1),
position('.' in substr(field1, position('step' in field1), length(field1)))-1
)
end as ans
from test;
Result:
+------------------------------------+------+------+-------+
| field1 | step | dot | ans |
+------------------------------------+------+------+-------+
| sometext.step1 | 10 | 10 | step1 |
| sometext.step1.cards.choice_step_1 | 10 | 16 | step1 |
| sometext.step1.cards.choice_step_2 | 10 | 16 | step1 |
| sometext.step1.desire | 10 | 16 | step1 |
| sometext.step2 | 10 | 10 | step2 |
| sometext.step2.cards.choice_step_1 | 10 | 16 | step2 |
| sometext.step2.cards.choice_step_2 | 10 | 16 | step2 |
| sometext.step2.desire | 10 | 16 | step2 |
| step1 | 1 | 1 | step1 |
+------------------------------------+------+------+-------+
Notice the last field that has the data you desire. Please feel free to tweak this to your needs.