Thread RegEx Problem (13 answers)
Opened by Gast at 2006-12-01 16:06

badblock
 2006-12-01 23:06
#72147 #72147
User since
2006-06-01
10 Artikel
BenutzerIn
[default_avatar]
[quote=opi,01.12.2006, 17:37]
Code: (dl )
/^(.*?)([\w.]*) like ('.*')(\s*and.*)$/


Aber das hilft dir wohl auch nur für dieses eine Beispiel weiter...
Vielleicht ist es dir möglich, irgendwie mit split / and / zu arbeiten.
Statt des "and" in der Splitanweisung muss natürlich was intelligenteres
her.[/quote]
Quote
Code: (dl )
/^(.*?)([\w.]*) like ('.*')(\s*and.*)$/


Das ist leider auch nicht ganz wasserdicht, denn:
anstatt "and" kann auch ein "or" kommen (oder auch gar nichts mehr),
Also noch ein Beispielstring:
Code: (dl )
some.col = 4 and my.col like 'a''b''c' and another.col = 'xy' and a.b = 3

Hier soll das Ergegnis so aussehen:
Code: (dl )
1
2
3
4
1: some.col = 4 and
2: my.col
3: 'a''b''c'
4: and another.col = '123' and a.b = 3


Wenn ichs mir genau überlege, ist das aber noch komplizierter, denn es könne ja auch so einen Fall geben:
Code: (dl )
some.col like 'ab'' cd.ef like ' and my.col like 'xyz'


Gewünschtes Ergebnis:
Code: (dl )
1
2
3
4
1: some.col like 'ab'' cd.ef like ' and
2: my.col
3: 'xyz'
4: (undef)


Um das wirklich wasserdicht zu bekommen, muss ich einen SQL-Parser neu erfinden, oder?

View full thread RegEx Problem