Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Regex # Special Character Escape

Solved Go to solution
Highlighted

Regex # Special Character Escape

New Contributor

I'm trying to use regex to match the line:
# DOG CAT BIRD

NiFi regex seems to treat # as a comment character, whereas other regexes do not.

How do I match the literal character # in a string with regex?


The doc page https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#escaping doesn't seem to help me out here.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Regex # Special Character Escape

Master Guru

@Nick Stantzos

You can ignore the unexpected coloring rendered by the NiFi Expression language editor window.
The java regex replace should work just using "# DOG CAT BIRD" or "\# DOG CAT BIRD".


Thank you,

Matt

4 REPLIES 4

Re: Regex # Special Character Escape

Contributor

Did you try using '\' character?

Re: Regex # Special Character Escape

New Contributor

With the '\' character, the '#' character still highlights the text after it as a comment:

108373-1556809188675.png

Re: Regex # Special Character Escape

Master Guru

@Nick Stantzos

You can ignore the unexpected coloring rendered by the NiFi Expression language editor window.
The java regex replace should work just using "# DOG CAT BIRD" or "\# DOG CAT BIRD".


Thank you,

Matt

Re: Regex # Special Character Escape

New Contributor

Thanks Matt, I didn't realize that the colored text was not a comment in this case.

Don't have an account?
Coming from Hortonworks? Activate your account here