6

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!

2
  • 2
    This site should help you easily test your regular expressions against multiple strings and compare the results. As for the regex format, just read the docs. Commented Nov 13, 2012 at 9:57
  • @Tom, that site is super helpful, thanks! Commented Nov 13, 2012 at 10:04

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I will definitely look there, any good sites for learning regex expressions in general?
@JoeCrawley that site has one of the best regex tutorials, too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.