CARVIEW |
Select Language
HTTP/2 200
date: Mon, 21 Jul 2025 17:58:34 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"9deb029052737d2d76554ee7e0fad98e"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=fmIl%2BAXAHYBXc6%2FsGhsDvg4KYj6xfKjGtuQyi6b6R4wg8tsmPVsdokvI60%2FDU9VRwD9SwuaDGJqLeWwNmAzDWJRMiur0E8dIakpUou9Ck8dEpvY7%2F324jOyed%2BWR9dwW0hOkW016gvQQRc0L5EzeAYQfNv81Kd8KKDk74rBR%2FIulVLWrveSZE3di9CPxFI83FGRYzhmXg4FePrsMMySTcDUKAIVPMNsXyHLA7M13qzFnG2xB9U1QtwGiakZcZNmWmJkrjF7JcjfSveVjxXMe2w%3D%3D--KYbDcTiy%2B4LdWSs4--SMn0hERuP2eLjm2ItLFZJw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.680905404.1753120714; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 17:58:34 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 17:58:34 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: DBC8:36EDF7:1EBB6B:2453AA:687E7FCA
Parse long strings example · VerbalExpressions/JavaVerbalExpressions Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 241
Parse long strings example
Merkushev Kirill edited this page Jun 4, 2014
·
2 revisions
Given lines to parse:
3 4 1 https://localhost:20001 1 28800 0 528800 1000000000 0 528800 STR1
3 5 1 https://localhost:20002 1 28800 0 528800 1000020002 0 528800 STR2
4 6 0 https://localhost:20002 1 48800 0 528800 1000000000 0 528800 STR1
4 7 0 https://localhost:20003 1 48800 0 528800 1000020003 0 528800 STR2
5 8 1 https://localhost:20003 1 68800 0 528800 1000000000 0 528800 STR1
5 9 1 https://localhost:20004 1 28800 0 528800 1000020004 0 528800 STR2
Take one to write test:
String logLine = "3\t4\t1\thttps://localhost:20001\t1\t63528800\t0\t63528800\t1000000000\t0\t63528800\tSTR1";
Simply write all what we see (remember that we need to save every column):
VerbalExpression regex = regex()
.capt().digit().oneOrMore().endCapture().tab() // 3
.capt().digit().oneOrMore().endCapture().tab() // 4
.capt().range("0", "1").count(1).endCapture().tab() // 1 (or 0)
.capt().find("https://localhost:20").digit().count(3).endCapture().tab() // https://localhost:20001
.capt().range("0", "1").count(1).endCapture().tab() // again 1 (or 0)
.capt().digit().oneOrMore().endCapture().tab() // 63528800 (lots of digits)
.capt().range("0", "1").count(1).endCapture().tab() // again 1 (or 0)
.capt().digit().oneOrMore().endCapture().tab() // again lots of digit
.capt().digit().oneOrMore().endCapture().tab() // ... and again
.capt().range("0", "1").count(1).endCapture().tab() // 1 (or 0)
.capt().digit().oneOrMore().endCapture().tab() // ... and again
.capt().find("STR").range("0", "2").count(1).endCapture().build(); // at last STR1
Now we can check matching (with help of simple matcher)
assertThat(regex, matchesExactly(logLine)); // Hooray! It matches.
This regexp looks like: ((?:\d)+)(?:\t)((?:\d)+)(?:\t)([0-1]{1})(?:\t)((?:http\:\/\/localhost\:20)(?:\d){3})(?:\t)([0-1]{1})(?:\t)((?:\d)+)(?:\t)([0-1]{1})(?:\t)((?:\d)+)(?:\t)((?:\d)+)(?:\t)([0-1]{1})(?:\t)((?:\d)+)(?:\t)((?:STR)[0-2]{1})
. Wow! You can match it yourself with help of RegexPlanet. But usually you don't need to see that form.
I think you see how much "again" words in comments. Let's get rid of duplication! Group same in that way:
VerbalExpression.Builder digits = regex().capt().digit().oneOrMore().endCapt().tab();
VerbalExpression.Builder range = regex().capt().range("0", "1").count(1).endCapt().tab();
VerbalExpression.Builder host = regex().capt().find("https://localhost:20").digit().count(3).endCapt().tab();
VerbalExpression.Builder str = regex().capt().find("STR").range("0", "2").count(1);
Now we have 4 groups for use:
VerbalExpression regex2 = regex()
.add(digits).add(digits)
.add(range).add(host).add(range).add(digits).add(range)
.add(digits).add(digits)
.add(range).add(digits).add(str).build();
And recheck:
assertThat(regex2, matchesExactly(logLine)); // still matches!
You can try working example in unit-tests section: RealWorldUnitTest
You can’t perform that action at this time.