0

One of the column in my table have data like this

@Stream<TTL>@Topic<Abstimmung_Carbon_Accounting>@Date<03-May-2012<@Time<BN,APH>@Participants<MUELLER,RECHTE>@Pages<2>
@Stream<m20>@Topic<Shared_Space_Afternoon>@Date<12.10.12>@Time<Call>@Participants<dehaan>@Pages<2>

What I want is to select the Topic part only, using mysql query. Regex for this is something like Topic\<\w+\>

But how to use it to select part from a field in mysql.

Output needed:

Abstimmung_Carbon_Accounting

Shared_Space_Afternoon

Thanks for your help.

2
  • 4
    MySQL regexes can match only. You can't capture/extract from a string with them. That will have to be done in client-side code. Commented Dec 10, 2013 at 14:42
  • If you need to extract data from a column, it will perhaps be useful to add more columns to your table or rethink the structure of your database. Commented Dec 10, 2013 at 15:08

1 Answer 1

1

You can solve this problem without using regex

Assume you have a table table2 with one column col1 of varchar type and it contain following values

@Stream<TTL>@Topic<Abstimmung_Carbon_Accounting>@Date<03-May-2012<@Time<BN,APH>@Participants<MUELLER,RECHTE>@Pages<2>
@Stream<m20>@Topic<Shared_Space_Afternoon>@Date<12.10.12>@Time<Call>@Participants<dehaan>@Pages<2>

Then you can use following query to get your required output

select substring(col1,Locate('Topic<',col1)+6,(Locate('>',substring(col1,Locate('Topic<',col1)+6))-1)) as result  from table2 
where substring(col1,Locate('Topic<',col1))!=""
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.