cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

regexp_extract Error when put { in pattern

William_Scardua
Valued Contributor

HI guys,

I tried to use the regex_extract but when I put { in pattern I received error

display(
    df_containerlog.withColumn('reg', regexp_extract(col('LogEntry'), "((^.*))({'data':)", 1))
)

 

error-regex.png

have any idea

Thank you

2 REPLIES 2

-werners-
Esteemed Contributor III

what do you want to achieve with the curly brace?  It is a regex character so you can't just add it.
If you want to match on it, you should escape it and perhaps even put it within the quotes.
You can always test your regex in online tools like regex101 or regexr or ... very handy

Amine
New Contributor III
New Contributor III

Hello William,

You have to escape the { as it is a special char in case of regex.

"((^.*))(\{'data':)"
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.