Jump to content

Regular expression challenge for stripping single comments.


guinness
 Share

Go to solution Solved by DXRW4E,

Recommended Posts

That's very difficult to read to me and requires a bit of thinking to figure out its logic.  I'm not saying its bad or wrong, just a bit complicated looking.

Is all OK, however is only this

'(?:[^;"''\r\n]|''[^''\r\n]*''|"[^"\r\n]*")*'

is the ABC of regex the first thing that you see all over the web

'(?:[^"]|"[^"]*")*'

I was referring to this

the example above refers to read the string into quotes, for this is a bit more complicated

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Ascend4nt,

 

Although I still hope future versions of PCRE add the ability to search for anything not-of-a-capture-group back..

I was about posting a question about this point on the PCRE list but before I'd like to come up with a real-world example where such a feature is useful.

If you have a captured group, then want to skip until that group, that means that you expect to see that again, so tell the engine you want to match that.

(abc|def) .*? \g-1
matches
abcXXXXXX YYYYYYabc

If you're not so sure that the group reappears, make it optional:

(abc|def) .*? \g-1?
matches
abcXXXXXX YYYYYYabc
and
abcXXXXXX YYYYYY

From this point of view I don't have an example of a situation where a back-ref to a group would be needed in a class. Can anyone surprise me?

Of course if you want to match a different final boundary you can still use a reference to subroutine:

(abc|def) .*? (?-1)
matches
abcXXXXXX YYYYYYabc
and
abcXXXXXX YYYYYYdef
(and other combinations)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

jchd, hmm.. good question.  I was thinking about the possiblity of using that to detect duplicate things like 'patient_id = 124ab' but there are other means to do that. And from a few trials with the old engine it seems like the feature was actually broken, as it skipped over the captured groups in most cases.  Oh, and oddly it seems to require curly braces for backreferences g{-1} and I swore in one case I had to use it with an absolute number even if followed by a bracket. 

Overall I suppose its not something to pester them about (unless its deviating from a Posix standard?).  The 'detect duplicates' thought I had can be solved with lookahead and lookbehind assertions.  And as you point out, if we're looking for a specific group to reappear we have other tools at our disposal.

Link to comment
Share on other sites

I asked the question on the pcre list and I'll keep you informed of the outcome.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...