On Feb 12, 2007, at 11:16 AM, Chuck Pelto wrote:

Morning Charles,

On Feb 11, 2007, at 8:56 AM, Charles Yeomans wrote:


On Feb 10, 2007, at 12:54 PM, Chuck Pelto wrote:

Greetings,

Where can I find a good site to go to for advice on how to code a RegEx request that will allow for double-quotation marks while excluding any that are preceded by a symbol indicating an ESCAPE character?


I'd suggest the REALbasic mailing lists. We'd need a little more information about the regular expression you're trying to write.

I'm trying to write a RegEx call that will identify text between pairs of doube-quotation marks, excluding any such mark that is preceded by an ESCAPE character. The ESCAPE character, for the sake of discussion, is the backwards slash (\) character.

Therefore, in a string of text from and EditField that reads as follows:

This is a test by "Chuck Pelto" for "Susan Pelto" done in "\"Olde\" English"

It would find the following items:

[1] "Chuck Pelto"
[2] "Susan Pelto"
[3] ""Olde" English"

I've got the part of getting the stuff between double-quotation marks working. It reads as follows:

  // method to test aspects of Regular Expressions

  dim rg as New RegEx
  dim theMatch as RegExMatch

  dim strInput as string
  dim strQuots as string
  dim srchPatt as string

  dim iCount as integer
  dim i as integer

  iCount = 0

  strInput = EditField1.text

srchPatt = chr(34) + ".*?" + chr(34) // HERE is the pattern that looks for text between double-quotation marks in a non-greedy manner

  rg.SearchPattern = srchPatt

  theMatch = rg.Search(strInput)

  while theMatch<> nil
    iCount = iCount + 1
    strQuots = theMatch.subExpressionString(0)
    theMatch = rg.search()
  wend



What I need now is to figure out how to get it to exclude double- quotation marks that are preceded by the ESCAPE character (\).

I'm learning how to do this using TextWrangler.

I'm toying around with the following variation on the basic search pattern.....

  srchPatt = chr(34) + ".*?" + chr(34) + "[^(\")]"

Do you think THAT would work?

No.  But the following does appear to work.

rg.SearchPattern = "\x22.*?(?<!\\)\x22"

In other words -- match ", then keep matching until you hit a " not preceded by \.

See the section entitled "Extension Mechanism" in the RegEx documentation for explanation of this incantation.

Charles Yeomans

P.S. The Getting Started list is being killed off, so I've moved this to the NUG.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to