I am trying to use regex in Delphi to regex HTML and retrieve some data.
My goal is to create a query string followed by sintax:
?namedGroup1=valueNamedGroup1&namedGroup2=valueNamedGroup2
I have n Regular Expression Array:
array[0] = '<div (id="(?<id>[a-zA-Z0-9]+)"|name="(?<name>[a-zA-Z0-9]+))"';
My html:
<h1>bla bla bla</h1> <div id="home">
If I applied this regular expression using the built-in regular expression in PHP, it will return an associative array
RegArray[0] = '<div id="home">'
RegArray['id'] = 'home'
if I do foreach, I easily get a list of named groups, and I can create my query:
?id=home
The thing is, I don’t know if the regular expression will match the named group identifier or name, and I need to know that.
Delphi returns only a simple array
RegArray[0] = '<div id="home">'
RegArray[1] = 'home' // ID or NAME?
So, how do I get the named group and the named value of Group?
here it is my code:
var RegEx: TRegEx;
begin
RegEx := TRegEx.Create(array[0], [roIgnoreCase,roMultiline]);
Match := RegEx.Match(html);
if (Match.Success) then
begin
//get the group here.
end;
: http://www.regular-expressions.info/delphi.html