Getting content within square bracket


(paul walker) #1

Hi Folks

If %asset_name% returns “[123456] - My asset name”, how can I modify the code to show just the content of the brackets ie; 123456 ?

Have looked around a bit and cannot find the answer to this question

Thanks in advance

Paul


(Nic Hubbard) #2

Is the number the asset ID?


(paul walker) #3

Hi Nic, thank you for responding - no, the asset (a data record) is a the name of a course and it’s code ie;

[75FR015] Introduction to Open Cast Treacle Mining

I just want to separate the course code from the brackets and the rest of the course name ie;

75FR015


#4

You could use a regular expression asset to capture the value.
/\[(\w*)\].*/

If the regular expression asset number is 5555, you could then print the value like:
%asset_name^preg_match_result:5555^index:1^index:0%

If you needed to refer to this more than once or twice I’d be inclined to stick it in the default value for a metadata field applied to those assets, and reference the metadata field instead.