makarms / text-probe
Simple and extensible PHP library for text analysis and pattern matching, designed to help developers probe, parse, and manipulate text efficiently.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 0
Forks: 2
Open Issues: 2
pkg:composer/makarms/text-probe
Requires
- php: >=8.1
- ext-mbstring: *
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- ergebnis/composer-normalize: ^2.48
- friendsofphp/php-cs-fixer: ^3.89
- icanhazstring/composer-unused: ^0.9
- infection/infection: ^0.29
- phpcompatibility/php-compatibility: ^9.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10
- squizlabs/php_codesniffer: ^3.8
README
TextProbe is a simple and extensible PHP library for text analysis and pattern matching. It is designed to help developers probe, parse, and manipulate text efficiently using customizable rules and matchers.
Features
- π§ Easy-to-use API for text matching and parsing
- π§ Extensible architecture β write your own matchers and rules
- π‘ Suitable for parsing logs, user input, or any structured text
Installation
You can install the library via Composer:
composer require makarms/text-probe
Available Probes
The library comes with several built-in probes to detect common patterns in text:
π§βπ» Contact & Identity
-
DiscordNewUsernameProbeβ extracts Discord usernames in the new format (e.g.,@username), enforcing Discordβs updated naming rules (length, characters, no consecutive dots). -
DiscordOldUsernameProbeβ extracts classic Discord usernames in the formatusername#1234, ensuring proper structure and valid discriminator. -
EmailProbeβ extracts email addresses. -
RussianPassportNumberProbeβ extracts Russian internal passport numbers (series and six-digit number), supporting spaces or dashes between parts with basic structure validation. -
PhoneProbeβ extracts phone numbers (supports various formats). -
RussianInnProbeβ extracts Russian tax identification numbers (INN) for organizations (10 digits) and individuals ( 12 digits), validating checksums. -
RussianSnilsProbeβ extracts Russian SNILS numbers (11 digits with checksum), supporting compact or dashed formats like11223344595or112-233-445 95. -
SlackUsernameProbeβ extracts Slack usernames (e.g.,@username), supporting Slack-specific username rules such as allowed characters, length limits, and no consecutive dots. -
InstagramUsernameProbeβ extracts Instagram usernames (e.g.,@username), allowing letters, digits, underscores, and dots while rejecting invalid boundaries or consecutive dots. -
TelegramUserLinkProbeβ extractst.melinks pointing to Telegram users. -
TelegramUsernameProbeβ extracts Telegram usernames (e.g.,@username). -
UsSocialSecurityNumberProbeβ extracts U.S. Social Security Numbers (SSN) in theXXX-XX-XXXXformat while discarding structurally invalid area, group, or serial combinations.
π Date & Time
-
DateProbeβ extracts dates in various formats (e.g.,YYYY-MM-DD,DD/MM/YYYY,2nd Jan 2023). -
DateTimeProbeβ extracts combined date and time in multiple common formats. -
TimeProbeβ extracts times (e.g.,14:30,14:30:15, optional AM/PM).
π° Finance
π§Ύ Prices
PriceProbeβ extracts price expressions combining numeric amounts with currency symbols (e.g.,$199,1 500β½) or ISO currency codes, including slash-separated pairs (e.g.,100 USD,99 EUR/UAH). Supports spaces or commas as thousand separators and dots or commas for decimal fractions.
π’ Company Registration
RussianOgrnNumberProbeβ Extracts Russian OGRN numbers (13 digits) and validates the checksum.
π¦ Bank Account
-
BankBicCodeProbeβ Extracts SWIFT/BIC codes (8β11 characters, e.g.,DEUTDEFF500). -
BankIbanNumberProbeβ Extracts IBAN numbers, supports spaces, validates using Mod-97. -
BankRoutingNumberProbeβ Extracts US Routing Numbers (9 digits), validates the checksum.
π³ Bank Cards
Supported formats: plain digits (e.g.,
4111111111111111), digits separated by spaces (e.g.,4111 1111 1111 1111) or dashes (e.g.,4111-1111-1111-1111). Only Luhn-valid numbers by default.
-
BankCardNumberProbeβ extracts major card schemes like Visa, Mastercard, Amex, and all other supported schemes listed below. -
BankAmexCardProbeβ American Express (prefixes: 34, 37), 15 digits. -
BankDinersClubCardProbeβ Diners Club (prefixes: 30[0-5], 309, 36, 38, 39), 13β14 digits. -
BankDiscoverCardProbeβ Discover (prefixes: 6011, 65, 644β649, 622126β622925), 16 digits. -
BankJcbCardProbeβ JCB (prefixes: 3528β3589), 16 digits. -
BankMaestroCardProbeβ Maestro (prefixes: 5018, 5020, 5038, 5612, 5893, 6304, 6759, 6761β6763), 16β19 digits. -
BankMastercardCardProbeβ Mastercard (prefixes: 51β55, 2221β2720), 16 digits. -
BankMirCardProbeβ MIR (prefixes: 2200β2204), 16 digits. -
BankRupayCardProbeβ RuPay (prefixes: 508, 60, 65, 81, 82), 16 digits. -
BankTroyCardProbeβ Troy (prefixes: 9792), 16 digits. -
BankUnionpayCardProbeβ UnionPay (prefixes: 62), 16β19 digits. -
BankVerveCardProbeβ Verve (prefixes: 5060, 5061, 6500β6509), 13β19 digits. -
BankVisaCardProbeβ Visa (prefixes: 4), 13β19 digits.
π Card Security & Expiration
-
BankCardCvvCvcCodeProbeβ Extracts CVV/CVC codes (3β4 digits). -
BankCardExpiryProbeβ Extracts card expiration dates (formatsMM/YY,MM/YYYY,MM-YY,MM-YYYY, etc.).
π Crypto
-
BitcoinAddressProbeβ Extracts Bitcoin addresses (Base58 and Bech32 formats). -
EthereumAddressProbeβ Extracts Ethereum addresses (0x-prefixed, 40 hex characters). -
LitecoinAddressProbeβ Extracts Litecoin addresses (Base58 or Bech32). -
RippleAddressProbeβ Extracts Ripple/XRP addresses (starts with 'r', Base58). -
SolanaAddressProbeβ Extracts Solana addresses (Base58, 32β44 chars). -
TronAddressProbeβ Extracts TRON addresses (Base58, starts with 'T', 34 chars). -
UsdcAlgorandAddressProbeβ Extracts USDC addresses on Algorand (Base32, 58 chars). -
UsdcErc20AddressProbeβ Extracts USDC ERC20 addresses (Ethereum-compatible, 0x-prefixed). -
UsdcSolanaAddressProbeβ Extracts USDC addresses on Solana (same format as Solana addresses). -
UsdtErc20AddressProbeβ Extracts USDT ERC20 addresses (Ethereum-compatible, 0x-prefixed). -
UsdtOmniAddressProbeβ Extracts USDT Omni addresses (Bitcoin-based, starts with 1 or 3, 26β35 chars). -
UsdtTrc20AddressProbeβ Extracts USDT TRC20 addresses (TRON-based, Base58, starts with 'T', 34 chars).
πΊ Geolocation
-
GeoCoordinatesProbeβ extracts geographic coordinates in various formats (decimalordegrees/minutes/seconds,N/S/E/W). -
PostalCodeProbeβ extracts postal codes across multiple regions, including US ZIP (+4), Russian six-digit, UK, Canadian, and Dutch-style codes.
π· Social & Tags
HashtagProbeβ extracts hashtags from text (e.g.,#example), supporting Unicode letters, numbers, and underscores, detecting hashtags in any position of the text.
βοΈ Text
AllCapsSequenceProbeβ extracts sequences of two or more consecutive uppercase letters (Unicode-aware), making it easy to detect acronyms or emphasised ALL CAPS tokens in text.
π UUID & Identifiers
-
HexHashProbeβ extracts common hexadecimal hash strings such as MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512, matching 32β128 hex characters while avoiding partial matches inside longer strings. -
UUIDProbeβ extracts any valid UUID (v1βv6) without checking the specific version. Supports standard UUID formats with hyphens. -
UUIDv1Probeβ extracts UUID version 1, matching the formatxxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxx, commonly used for time-based identifiers. -
UUIDv2Probeβ extracts UUID version 2, matching the formatxxxxxxxx-xxxx-2xxx-xxxx-xxxxxxxxxxxx, typically used in DCE Security contexts. -
UUIDv3Probeβ extracts UUID version 3, matching the formatxxxxxxxx-xxxx-3xxx-xxxx-xxxxxxxxxxxx, generated using MD5 hashing of names and namespaces. -
UUIDv4Probeβ extracts UUID version 4, matching the formatxxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx, randomly generated and commonly used for unique identifiers. -
UUIDv5Probeβ extracts UUID version 5, matching the formatxxxxxxxx-xxxx-5xxx-xxxx-xxxxxxxxxxxx, generated using SHA-1 hashing of names and namespaces. -
UUIDv6Probeβ extracts UUID version 6, matching the formatxxxxxxxx-xxxx-6xxx-xxxx-xxxxxxxxxxxx, an ordered version for better indexing and sorting. -
CarVinProbeβ extracts vehicle identification numbers (VINs), enforcing allowed characters and validating the checksum digit.
βοΈ Versioning
SemanticVersionProbeβ extracts semantic version numbers inMAJOR.MINOR.PATCHformat with optional pre-release identifiers and build metadata, ensuring numeric identifiers avoid leading zeros while supporting dot-separated alphanumeric segments.
π Web & Network
-
DomainProbeβ extracts domain names, including internationalized (Unicode) domains. -
IPv4Probeβ extracts IPv4 addresses, supporting standard formats and excluding reserved/bogus ranges if necessary. -
PrivateIPv4Probeβ extracts private IPv4 addresses from the 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 ranges. -
IPv6Probeβ extracts IPv6 addresses, including compressed formats, IPv4-mapped addresses, and zone indexes (e.g.,%eth0). -
LinkProbeβ extracts hyperlinks, including ones with IP addresses, ports, or without a protocol. -
GithubRepositoryLinkProbeβ extracts GitHub repository links over HTTP/HTTPS, supporting optional.gitsuffixes, additional paths, and trimming trailing punctuation. -
GoogleDocsLinkProbeβ extracts Google Docs, Sheets, Slides, and Forms links hosted on docs.google.com. -
CookieProbeβ extracts HTTP cookie key/value pairs fromSet-CookieorCookieheaders, filtering out common attributes likePathorExpires. -
HtmlTagProbeβ extracts HTML tags, returning full paired segments with their content or standalone/self-closing tags. -
HexColorProbeβ extracts CSS-style hexadecimal color codes (#fff,#ffffff), ensuring only 3- or 6-digit values are matched while ignoring longer hexadecimal tokens. -
RgbRgbaColorProbeβ extracts RGB/RGBA color strings (e.g.,rgb(255,0,0),rgba(255,0,0,0.5),255,0,0). -
MacAddressProbeβ extracts MAC addresses in standard formats using colons or hyphens (e.g.,00:1A:2B:3C:4D:5Eor00-1A-2B-3C-4D-5E), accurately detecting valid addresses while excluding invalid patterns. -
JwtTokenProbeβ extracts JSON Web Tokens (JWT) in compact format (xxxxx.yyyyy.zzzzz), supporting Base64url segments with optional padding. -
UserAgentProbeβ extracts User-Agent strings from text, supporting complex structures like multiple product tokens, OS information, and browser identifiers. -
FilePathProbeβ extracts absolute file paths in Linux (e.g.,/etc/passwd) and Windows (e.g.,C:\\Windows\\System32) formats.
π³ Docker
-
DockerImageProbeβ extracts Docker image names with tags only (e.g.,nginx:1.25.1,redis:latest,ghcr.io/app/api: v2). Supports registries, multi-level namespaces, semantic and custom tags, while ignoring invalid or tagless image names (e.g., python, myapp/web). -
DockerContainerIdProbeβ extracts Docker container IDs in short and full formats from logs and CLI output (e.g., docker ps, docker logs, CI, orchestration traces). Detects lowercase hexadecimal IDs of 12 or 64 characters, ignoring strings of other lengths or with non-hex characters. -
DockerLabelProbeβ extracts Docker label key/value pairs from Dockerfiles and CLI commands (e.g.,LABEL version="1.0.0" description="API" vendor=acme). Detects fragments in the formkey=valueandkey="value", including multiple labels in a single instruction, without fully parsing Dockerfile syntax. -
DockerCliFlagProbeβ extracts Docker CLI flags from arbitrary text (e.g.,-p 8080:80,-v ./src:/app,--env KEY=VALUE,--name api,--rm). Detects short and long options in both space and equals forms, with or without arguments, making it suitable for parsing docker run commands, CI scripts, and orchestration logs without full CLI parsing. -
DockerfileInstructionProbeβ extracts Dockerfile instructions such asFROM,RUN,COPY,ENV,HEALTHCHECK, including multiline continuations with\. Matches instruction blocks regardless of indentation and supports case-insensitive detection of all core Dockerfile directives. -
DockerImageDigestProbeβ extracts Docker image digests in the formsha256:<64-hex>from logs, Docker/registry output and SBOM metadata, including references likeimage@sha256:<digest>, while always returning only the digest value.
You can implement your own probes by creating classes that implement the IProbe interface.
Each probe also supports using a different validator for the returned values by passing an instance of a class
implementing the IValidator interface to the probeβs constructor. This allows you to override the default validation
logic.
For example, BankCardNumberProbe uses a default validator based on the Luhn algorithm, but you can provide your
own validator if you want to enforce additional rules, such as limiting to specific card issuers or formats.
Usage Example
require __DIR__ . '/vendor/autoload.php'; use TextProbe\TextProbe; use TextProbe\Probes\Contact\EmailProbe; $text = "Please contact us at info@example.com for more details."; $probe = new TextProbe(); $probe->addProbe(new EmailProbe()); $results = $probe->analyze($text); foreach ($results as $result) { echo sprintf( "[%s] %s (position %d-%d)\n", $result->getProbeType()->name, $result->getResult(), $result->getStart(), $result->getEnd() ); }
Expected output
[EMAIL] info@example.com (position 21-37)