1 Replies - 838 Views - Last Post: 20 November 2009 - 10:24 AM Rate Topic: -----

#1 ethan.pippitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-October 09

RegEx for Strings

Posted 19 November 2009 - 05:37 PM

I am trying to write a regex for a string based on this description. A string is a sequence of characters beginning and ending with a double-quote mark (") and with any other normal character in between. The delimiting quotes are not considered part of the string, but should be kept with the string token for this exercise. A double-quote mark is allowed inside of the string when preceded by a backslash (\); for example: "I said, \"Hello!\"" is a string containing two double-quote marks.

Currently my regex posted below will work for all "strings" except something with \" text text \" in it. Help would be awesome.


  /^"[^"\r\n]*"$/  

This post has been edited by ethan.pippitt: 19 November 2009 - 05:39 PM


Is This A Good Question/Topic? 0
  • +

Replies To: RegEx for Strings

#2 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: RegEx for Strings

Posted 20 November 2009 - 10:24 AM

Removing the " from [^"\r\n] would allow it to match "Hello, \"Hi\", bye". The ^ inside [] is excluding "\r\n.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1