to Regex Range
Overview
Pass two numbers, get a regex-compatible source string for matching ranges.
Documentation
Typical usage scenario
to Regex Range turns a pair of numbers into a regular expression that matches every integer between them — and nothing else. Give it 1 and 99 and it returns (?:[1-9]|[1-9][0-9]), a pattern that matches 1, 5 and 99 but rejects 0 and 100. Writing that expression by hand is fiddly, easy to get subtly wrong and painful to review; deriving it from two numbers at runtime is not.
Use it wherever a numeric bound has to be expressed as a pattern rather than a comparison:
• Numeric validation on a text field. A Mendix String attribute with a regex validation rule cannot say "between 1 and 31". Generate the pattern from the bounds you already hold in configuration instead of hard-coding an expression nobody dares touch.
• Input masks and client-side field constraints. Widgets and HTML inputs that accept a pattern need a regex, not a min/max pair. Produce it from the same two numbers your domain model uses, so the mask and the business rule cannot drift apart.
• Search and filter expressions. When you build a text search, a log query or a filter over data that holds numbers as text, a range pattern lets you express "any port from 1 to 65535" in a single expression.
• Validating codes with an embedded number. Product codes, seat numbers, floor and room identifiers often carry a bounded number in the middle. Splice a generated range pattern into than enumerating the alternatives by hand.
• Date and time fragments. Months (1–12), days (1–31) and year windows (1900–2099 gives (?:190[0-9]|19[1-9][0-9]|20[0-9]{2})) are
the classic cases where a handwritten pattern quie
• Configuration-driven rules. Because the bounds are parameters, an administrator can change the permitted range and the validation
pattern follows, with no redeployment of a hard-co
The underlying problem is that regular expressionss, so there is no natural way to write "between 18and 99" — you have to decompose the range digit by digit into (?:1[89]|[2-9][0-9]). This module does that decomposition for you,
using a library validated against more than 2.78 m
Features and limitations
• Client-side only. It runs in a nanoflow and cannot be called directly from a server-side microflow.
• Integers only. No decimal or fractional ranges, dix Integer bounds.
• It returns a pattern, not a match. The action generates the regex source only — it does not test a string, anchor the pattern or add delimiters. Add ^ and $ yourself for a whole-s
• No zero-padding support in practice. hasRelaxZeros only matters when bounds are supplied as zero-padded strings such as 01.Because the parameters are Integers, padding cannoever changes the output.
• The library's wrap option is not exposed. If you need the bare alternation, strip the wrapper yourself, or set hasCapture true and use the capturing form.
• No range lists and no step. One range per call, every integer in it.
• Long patterns for wide ranges. 1 to 2147483647 p hundred characters — correct, but not something toshow in a validation message.
• The example writes to a persistable entity, so i database even though the example never commits anobject.
Dependencies
• Mendix Studio Pro 10.24.17 or higher.
• Nanoflow Commons is required by the example — ACgress and HideProgress. It ships with every newMendix app; if removed from yours, add it back or delete the Example folder after import.
• Atlas Core is required by the example page, whicefault layout. Present by default.
• The JavaScript action itself has no Marketplace module dependencies.
• to-regex-range 5.0.1 and its single dependency iside the module package. Nothing is fetched at build or run time, so this works behind a firewall.
Installation
1. In Studio Pro 10.24.17 or higher, open App Explorer > Import module package and select toRegexRange.mpk.
2. Run Update project directory if prompted, so th is restored underjavascriptsource/toregexrange/actions.
3. Assign the toRegexRange.Admin module role to yoe and both example nanoflows allow Admin only — with just the User role you cannot open them.
4. Add ToRegexRangePage to your navigation to try ippet notes.
5. In your own nanoflow, add a JavaScript action activity and choose toregexrange from the toRegexRange module.
Configuration
Nothing to configure at module level. All behaviouparameters.
Known bugs.
None
Frequently Asked Questions
What exactly does the action return?
A regex source string, such as (?:[1-9]|[1-9][0-9]ern body only — no delimiters, no anchors and noflags.
Do I need to add anchors?
Almost always, yes. Without ^ and $ the pattern malonger string, so 123 would satisfy a 1-to-9pattern.
Can I call it from a microflow?
No. It is a JavaScript action, so it runs client-snanoflow from your microflow.
Does it work in a native mobile app?
Yes. The action's platform is set to All and the library uses no browser or platform-specific APIs.
Do I need to install anything with npm?
No. to-regex-range 5.0.1 and is-number 7.0.0 ship
Can I use decimal bounds?
No. Both parameters are Integers, so the module generates patterns for whole numbers only.
What happens if the minimum and maximum are the same?
You get that number as a string — 5 to 5 returns 5example page defaults to 0 and 0, so pressingConvert without changing anything returns 0.
What if I pass the bounds the wrong way round?
It still works. The library normalises the order, tern as 1 to 99.
Are negative numbers supported?
Yes. A range crossing zero produces both negative and positive alternatives — −10 to 10 gives (?:-[1-9]|-?10|[0-9]).
Why does the "relax zeros" toggle on the example page change nothing?
Because zero-padding cannot be expressed through aibrary never reaches the code that reads the option. See Known bugs.
What is the entity for — will it store data in my database?
It exists only to drive the example page. It is peadd a table, but the example never commits anobject. Delete the Example folder and the entity if you only want the action.
Which Studio Pro versions are supported?
10.24.17 and higher. This release was converted frTS line.
Issues, suggestions and feature requests:
Releases
**to Regex Range** — now supported on Mendix Studio Pro **10.24.17**
Rebuilt from Studio Pro 9.24.18 to **10.24.17** (LTS). No functional changes — this release only updates Studio Pro compatibility.
Import `toRegexRange.mpk` via *App Explorer > Import module package* in Studio Pro 10.24.17 or higher.
---
Pass two numbers, get a regex-compatible source string for matching ranges.
**Features**
**General**:
• **minValue** - Min Value.
• **maxValue** - Max Value.
• **Capture** - Wrap the returned value in parentheses when there is more than one regex condition. Useful when you're dynamically generating ranges.
• **shorthand**- Use the regex shorthand for [0-9].
• **relaxZeros**- This option relaxes matching for leading zeros when when ranges are zero-padded.
**Dependencies:**
• Mendix modeler 9.24.18.
**Issues, suggestions and feature requests**
[https://github.com/bharathidas/to-regex-range/issues](https://github.com/bharathidas/to-regex-range/issues)