is it possible to capture a sequence in regex, and that the parser does not stop at the end of a line ?
I search for a pattern <table … > and the “…” are on multiple lines
I only can extract <table … until the end of first line with the regex = “<table (.*)”
I cannot extract more than a line.
I’ll reiterate Kems regexrx already has a PILE of these kinds of examples built in and you can just use them
VERY worth the small amount he asks for it
You should avoid .* where possible as it’s too general and it doesn’t capture EOL by default. A better choice might be [^>]*.
However, if you really must use .*, turn Greedy off and turn DotMatchesNewline on in the RegEx.Options. You can do the same by prefixing your pattern with code[/code], which is more portable.
[quote=225564:@Norman Palardy]I’ll reiterate Kems regexrx already has a PILE of these kinds of examples built in and you can just use them
VERY worth the small amount he asks for it[/quote]
I already own it !
[quote=225576:@Kem Tekinay]You should avoid .* where possible as it’s too general and it doesn’t capture EOL by default. A better choice might be [^>]*.
However, if you really must use .*, turn Greedy off and turn DotMatchesNewline on in the RegEx.Options. You can do the same by prefixing your pattern with code[/code], which is more portable.[/quote]
thanks Kem, but the [^>]* doesnt work as there are other tags between the <table and
so it stops at the first “>” it encounters.
I tried <table [^</table>]* but it doesnt work either…
I want to extract the “name” attribute of the tag, and the field attributes of the table. I dont need the <table_extra> tag.
is it doable with a regex, or do I better deal with xmldocuments and iterate ?
You could get clever with loops and things and get yourself a neat little parser that will extract key value pairs from each tag. I never liked Xojo’s XML tools so I have no comment on which would technically be better.
Someone always manages to code for free when I make an offer to create a solution per my consulting rate.
However, available for hire if you need - send me an email.
[quote=225661:@Tim Parnell]You could get clever with loops and things and get yourself a neat little parser that will extract key value pairs from each tag. I never liked Xojo’s XML tools so I have no comment on which would technically be better.
Someone always manages to code for free when I make an offer to create a solution per my consulting rate.
However, available for hire if you need - send me an email.[/quote]
thanks but I’m able to do this the “heavy” way.
I find regex can be elegant, and would try with it this time, or with xmldocument if regex cannot handle such search
and Kem is such a Regex Guru that I cannot help myself asking here …
Thanks Scott, this answers my question.
only the order of the attributes is not guaranteed to be the same on each line
is there a trick to get the attributes anyway ?
do a search for each attribute at a time ?
or a good regex trick …?
\r assumes that carriage returns are the line delimiters. This might have to be adjusted.
The [\w|\W|\r] basically means everything as \w and \W are the inverse of each other and we are just adding \r to the mix. The pipes – | – are equivalent to OR
The question mark ? means that the search will stop at the first find of the >
\r assumes that carriage returns are the line delimiters. This might have to be adjusted.
The [\w|\W|\r] basically means everything as \w and \W are the inverse of each other and we are just adding \r to the mix. The pipes – | – are equivalent to OR
The question mark ? means that the search will stop at the first find of the >[/quote]
thanks for the “elegant” solution, Robert.
it works with a small fix : <table[\\w|\\W|\\r]*?</table> instead of <table[\\w|\\W|\\r]*?></table>