views:

21

answers:

1

Hi since hours im trying to get a regex which is able to find the following part in a string.

[TABLE|head,border|{
#TEXT|TEXT|TEXT#
TEXT|TEXT|TEXT
TEXT|TEXT|TEXT
TEXT|TEXT|TEXT
}]

Its from a simple self made WYSIWYG Editor, which gives the possibility to add tables. But the "syntax" for a table should be as simple as the one above.

No as there can be many of these table definitions, i need to find all with php's preg_match_all to replace them with the well known "" tag in html.

The regex iam trying to use for is the following:

/\[TABLE\|(.*)\|\{(.*)\}\]/si

The \x0A stays for a newline as my app is running on linux this is enough (works fine with simpler regex).

I use the online regex tester on functions-online.com.

The matches it gets are not really usefull. And if i have more than one TABLE definition like the one above, then the matches are completely useless. Because of the (.*) it covers all from starting from "head,border" going to the very last "|" character in the second TABLE definition.

I would like to get a list of matches giving me the complete table command one by one. Can anybode help. Didnt any regex after hours which makes this possible.

+1  A: 

This is because by default the .* will be a greedy match, assuming your code works correctly for an input containing only a single value. Placing a question mark after the two .*'s should prevent greedyness being an issue.

/\[TABLE\|(.*?)\|\{(.*?)\}\]/si
Cags
Oh my god it was only the missing question mark?Its working.Lost hours because of 2 characters. 8-|Thanks a lot Cags.
NovumCoder