{"id":24573109,"url":"https://github.com/perazz/fortran-regex","last_synced_at":"2026-02-03T13:35:10.856Z","repository":{"id":152531354,"uuid":"529321877","full_name":"perazz/fortran-regex","owner":"perazz","description":"Fortran port of the tiny-regex-c library","archived":false,"fork":false,"pushed_at":"2024-03-26T12:44:30.000Z","size":214,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-07T11:08:37.157Z","etag":null,"topics":["fortran","regex","regex-parser","regular-expression","regular-expressions"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perazz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-26T16:01:37.000Z","updated_at":"2025-01-05T02:37:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"ecf310e0-6754-474f-976c-435253e8d9e8","html_url":"https://github.com/perazz/fortran-regex","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"6a9ac932af6d713a0e2606a3a14cddbbc1f8b0e4"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/perazz/fortran-regex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perazz%2Ffortran-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perazz%2Ffortran-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perazz%2Ffortran-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perazz%2Ffortran-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perazz","download_url":"https://codeload.github.com/perazz/fortran-regex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perazz%2Ffortran-regex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29046659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","regex","regex-parser","regular-expression","regular-expressions"],"created_at":"2025-01-23T19:55:48.220Z","updated_at":"2026-02-03T13:35:10.827Z","avatar_url":"https://github.com/perazz.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"### fortran-regex\n\nFortran-regex is a Modern Fortran port of the [tiny-regex-c](https://github.com/kokke/tiny-regex-c) library for regular expressions. It is based on the original C implementation, but the API is modelled in Fortran style, which is similar to the intrinsic `index` function. \n\n### API\n\nThe main API is modelled around Fortran's `index` intrinsic function (which performs a simple search for a substring within a string): \n\n```fortran\n   ! Perform regex on a character string\n   result = REGEX(string, pattern [, length] [, [back]])\n```\n- If the pattern command is invalid, `result = -1`.\n- If no substrings with the given pattern are found, with a valid pattern `result = 0`. This is also returned if the string has zero length, and that is an acceptable answer for the input pattern.\n- Otherwise, if the pattern was found `result \u003e 0` equal to the leftmost location inside the string where the pattern can be found. If the `back` keyword is provided and `.true.`, the location of the rightmost occurrence is returned instead. `length` returns the number of consecutive characters that match this pattern \n\n### Arguments\n\n| Argument | Type | Intent | Description |\n| --- | --- | --- | --- |\n| `string` | `character(*)` | `in` | The input text |\n| `pattern` | `character(*)` | `in` | The regex command |\n| `length` | `integer` | `out` (optional) | Length of the matched pattern |\n| `back` | `logical` | `in` (optional) | If the BACK argument is present and `.true.`, the return value is the start of the last occurrence rather than the first. |\n\n\n\n### Object-oriented interface\n\nOne can also parse a regex pattern into a `type(regex_pattern)` structure, and use that instead of a string pattern. I have no idea why this should be useful, but at least it's given with a consistent interface\n\n### Overview\n\nThe original tiny-regex-c code has been significantly refactored, to:\n\n* Remove all references to `NULL` character string termination, and replace them with Fortran's string intrinsics (`len`, `len_trim`, etc.)\n* Remove all C escaped characters (`\\n`, `\\t`, etc), replace with Fortran syntax.\n* Even in presence of strings, use `pure` `elemental` functions wherever possible\n* It is a standalone module that has no external dependencies besides compiler modules.\n\n### Example programs\n\n```fortran\n! Demonstrate use of regex\nprogram test_regex\n   use regex_module\n   implicit none\n   \n   integer :: idx,ln\n   character(*), parameter :: text = 'table football'\n   \n   idx = REGEX(string=text,pattern='foo*',length=ln);\n\n   ! Prints \"foo\"\n   print *, text(idx:idx+ln-1)\n   \nend program\n```\n\n\n```fortran\n! Demonstrate use of object-oriented interface\nprogram test_regex\n   use regex_module\n   implicit none\n   \n   integer :: idx,ln\n   character(*), parameter :: text = 'table football'\n   type(regex_pattern) :: re\n   \n   ! Parse pattern into a regex structure\n   re = parse_pattern('foo*')\n   \n   idx = REGEX(string=text,pattern=re,length=ln);\n\n   ! Prints \"foo\"\n   print *, text(idx:idx+ln-1)\n   \nend program\n```\n\n### To do list\n\n - [X] Add a `BACK` optional keyword to return the last instance instead of the first.\n - [ ] Option to return ALL instances as an array, instead of the first/last one only.\n - [X] Replace fixed-size static storage with allocatable character strings (slower?)\n \n### Reporting problems\n\nPlease report any problems! It is appreciated. The original C library had hacks to account for the fact that several special characters are read in with escaped sequences, which partially collides with the escaped sequence options in regex. So, expect the current API to be still a bit rough around the edges.\n\n### License\n\nfortran-regex is released under the MIT license. The code it's based upon is in the public domain.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperazz%2Ffortran-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperazz%2Ffortran-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperazz%2Ffortran-regex/lists"}