0

I have searched a lot about how to ignore part of RegEx expression. Here's why.

RegEx example:

".*atan2\\(.*\\).*"

It will detect the function 'atan2' like so:

string.matches("return atan2(45, 23)")

But as I bring in another String:

string.matches("return atan2("+Integer.valueOf(XInString)+", 58)")

And if XInString looks like that: 45.7 regex will be affected of that dot, because regex will look like that then: "return atan2(45.7, 58)" and the point between 5 and 7 is a part of regex. Is there a way to ignore that part? For example:

string.matches("return atan2([45.7], 58)")

(The string between [ and ] is what i don't want regex to read)

Matrx007
  • 25
  • 7

1 Answers1

1

...the point between 5 and 7 is a part of regex. Is there a way to ignore that part?

Yes, you can escape that dot using Pattern.quote(XInString) like this :

"return atan2(" + Pattern.quote(XInString) + ", 58)"
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140