Search code examples
regexlooker-studiore2

Need to use regex to extract a part of a string


I'm a regex noob that's trying to use the regexp_extract() function in data studio to extract part of a string. Could you help me out?

I need to extract the part of the string that comes after 'May'. Everything before 'May' is exactly the same across all campaigns.

I've tried googling the solution and killed a lot of time on regexer.com but i can't figure it out

Current Campaign Name:                       
Xxxxx_xxxxx_PKN_Trueview_24th MayComedy Movie Fans18-24 
Xxxxx_xxxxx_PKN_Trueview_24th MaySouth Asian Film Fans18-24 
Xxxxx_xxxxx_PKN_Trueview_24th MayCricket Enthusiasts18-24   
Xxxxx_xxxxx_PKN_Trueview_24th MayMotorcycle Enthusiasts18-24    

Expected Campaign Names:
Comedy Movie Fans18-24
South Asian Film Fans18-24
Cricket Enthusiasts18-24
Motorcycle Enthusiasts18-24

EDIT: I'm trying to use this in data studio in the REGEXP_EXTRACT(Campaign,"regex_code_here") function. I think the acceptable syntax is re2.


Solution

  • You may actually use REGEXP_REPLACE here to remove all before and including May:

    REGEXP_REPLACE(Campaign, '.*May', '')
    

    See the regex demo:

    enter image description here