Support Questions

Find answers, ask questions, and share your expertise

Regex # Special Character Escape

avatar

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

avatar
Master Mentor

@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

View solution in original post

4 REPLIES 4

avatar
Contributor

Did you try using '\' character?

avatar

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

108373-1556809188675.png

avatar
Master Mentor

@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

avatar

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