Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex Differences between Java and Ruby

Tags:

java

regex

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!

like image 203
Joe Crawley Avatar asked Nov 13 '12 09:11

Joe Crawley


1 Answers

Here is a good place to start:

  • specifics for Java (mostly usage of regex in general)
  • specifics for Ruby (mostly usage of regex in general)
  • flavor comparison (mostly regex syntax and features)

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.

like image 58
Martin Ender Avatar answered Oct 12 '22 23:10

Martin Ender