cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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
Databricks Employee
Databricks Employee

Hello William,

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

"((^.*))(\{'data':)"

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group