QRegularExpressionMatch A:B/C to A,B,C
-
A:B/C to A,B,C
QString location = "192.168.2.101:1068/description.xml"; QRegularExpression RE("(:*)(/*)"); QRegularExpressionMatch REM = RE.match(location); QString IP = REM.captured(0); QString port = REM.captured(1); QString description = REM.captured(2);IP = "192.168.2.101"
port = "1068"
description = "description.xml" -
A:B/C to A,B,C
QString location = "192.168.2.101:1068/description.xml"; QRegularExpression RE("(:*)(/*)"); QRegularExpressionMatch REM = RE.match(location); QString IP = REM.captured(0); QString port = REM.captured(1); QString description = REM.captured(2);IP = "192.168.2.101"
port = "1068"
description = "description.xml" -
A:B/C to A,B,C
QString location = "192.168.2.101:1068/description.xml"; QRegularExpression RE("(:*)(/*)"); QRegularExpressionMatch REM = RE.match(location); QString IP = REM.captured(0); QString port = REM.captured(1); QString description = REM.captured(2);IP = "192.168.2.101"
port = "1068"
description = "description.xml"@sonichy
You could do it in two statements as @eyllanesc wrote. (Though it won't cope so easily if, say, the filename part is allowed to be a path with multiple/s, which I assume it could be.) I would probably do it with a regular expression, but you want 3 captured elements and your reg ex only calls for 2. It's really very simple. I would go something like (untested):QRegularExpression RE("([^:]*):([^/]*)/(.*)"); -
@sonichy
You could do it in two statements as @eyllanesc wrote. (Though it won't cope so easily if, say, the filename part is allowed to be a path with multiple/s, which I assume it could be.) I would probably do it with a regular expression, but you want 3 captured elements and your reg ex only calls for 2. It's really very simple. I would go something like (untested):QRegularExpression RE("([^:]*):([^/]*)/(.*)");@JonB
"192.168.2.104:1068/description.xml"
"192.168.2.104"
"1068"Code should change to this:
QString IP = REM.captured(1); QString port = REM.captured(2); QString description = REM.captured(3);Acturally, my full line is:
LOCATION: http://192.168.2.104:1068/description.xml
How to Match ? -
@JonB
"192.168.2.104:1068/description.xml"
"192.168.2.104"
"1068"Code should change to this:
QString IP = REM.captured(1); QString port = REM.captured(2); QString description = REM.captured(3);Acturally, my full line is:
LOCATION: http://192.168.2.104:1068/description.xml
How to Match ? -
@JonB
"192.168.2.104:1068/description.xml"
"192.168.2.104"
"1068"Code should change to this:
QString IP = REM.captured(1); QString port = REM.captured(2); QString description = REM.captured(3);Acturally, my full line is:
LOCATION: http://192.168.2.104:1068/description.xml
How to Match ?@sonichy said in QRegularExpressionMatch A:B/C to A,B,C:
Acturally, my full line is:
LOCATION: http://192.168.2.104:1068/description.xml
How to Match ?QUrl implements url parsing and provides access to the host, port, and file name among other things.