Processing 3 Escaping Regex Characters

I’m currently using the Regex .matches("") command Processing 3 to make an ipv4 address format verifier. I’ve currently got it working with the seperate sets of numbers but my problem is with the ‘.’ symbol. The ‘.’ symbol is traditionally treated as a wildcard in Regex and its the same here but for some reason I can’t escape the character by using the normal method of placing a “.” back slash in front of the character. When I try this I get the error of: “Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \)”. So I was just wondering if there’s any other way to get round this that I don’t know of?

1 Like


I am not familiar with regex but did a quick exploration of this.


void setup()
  String s = "";
  //String[] m = match(s, "\\.");
  String[] m = match(s, "\\.(.*?)\\.");
  println("Found '" + m[1] + "' inside the tag.");


Update (I had the py version above):


Oh thank you very much. It appears that you need to use two backslashes to escape characters. I’ve been stuck on this for a while. I’m very grateful for your help.

1 Like

For more on this, see the reference page for String:

Because a String is defined between double quotation marks, to include such marks within the String itself you must use the ** (backslash) character. (See the third example above.) This is known as an escape sequence . Other escape sequences include \t for the tab character and \n for new line. Because backslash is the escape character, to include a single backslash within a String, you must use two consecutive backslashes, as in: \

1 Like