Joe Crawley
Joe Crawley

Reputation: 725

Regex Differences between Java and Ruby

I'm trying to write a regex for:

  1. Strings of characters beginning and ending with a double quote character, that do not contain control characters, and for which the backslash is used to escape the next character.
  2. The paren-star form of comments in Pascal: strings beginning with (* and ending with *) that do not contain *)

I'm trying to write a version in Ruby, then another in Java, but I'm having trouble finding the differences in regex expressions for both. Any help is appreciated!

Upvotes: 6

Views: 1633

Answers (1)

Martin Ender
Martin Ender

Reputation: 44259

Here is a good place to start:

Mostly note that in Ruby your write regexes by delimiting them with /, and in Java you need to double-escape everything (\\ instead of \) so that the backslashes get through to the regex engine. Everything else you should find within those links I gave you above.

For the sake of completeness of this answer, I would also like to include Tom's Link to this online regex tester, that supports a multitude of regex flavors.

You should go ahead and give both regexes a go. If you encounter any problems, you are more than welcome to ask a new (specific) question, showing your own attempts.

Upvotes: 7

Related Questions