Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

50%
+0 −0
Challenges The 50 substrings that validate any string of Roman numerals

JavaScript, 149 bytes t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/) Simple regex. Retu...

posted 6mo ago by --Hyde‭  ·  edited 6mo ago by --Hyde‭

Answer
#3: Post edited by user avatar --Hyde‭ · 2024-05-25T08:16:14Z (6 months ago)
  • # JavaScript (V8), 149 bytes
  • ```
  • t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/)
  • ```
  • Simple regex. Returns `null` on valid strings.
  • [Try it online!][TIO-lwklk18h]
  • [JavaScript (V8)]: https://v8.dev/
  • [TIO-lwklk18h]: https://tio.run/##RVI9b0IxDNz7K94GSC2slRBd7CWSvUaWnhgQgn6oLagvYsp/fz3HQXiwHefu4jj5OtwO0/Hv81pebq/zeTeX3VtZ/xzK8WO5IVglGln3lXQkjxxL5spaE2qCVYLBjdmQZ6Q2UhJfSUcIKrKvCqu51Xw3B8X8DFHPuJpYNa0WBINtVvPx8juVoZymMg27YVykxfOwyO7Mnbgjd@xO3aXABChQAQtcADsyoBHQfxRzoFOEvrIIXYkicIS7WGOocESzOJBSamQlv1NkMIvjVMWod4AZkRp1uCoDJuDku7QTTXJoqPOibPxAMAQecGXQYxJxA5EWUWbVfjdmThqDyUKWsillk2g/S8KLol3LKn20eDNMC61xiPld1VEq0kXRE7QgLXjXpoQmjXwfdb3PDERGwcnRALO2KnpnwjPtt0/@By7fp/X35X3ZfgK@6XV5Xq228z8 "JavaScript (V8) – Try It Online"
  • # JavaScript, 149 bytes
  • ```
  • t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/)
  • ```
  • Simple regex. Returns `null` on valid strings.
  • [Try it online!][TIO-lwklk18h]
  • [JavaScript (V8)]: https://v8.dev/
  • [TIO-lwklk18h]: https://tio.run/##RVI9b0IxDNz7K94GSC2slRBd7CWSvUaWnhgQgn6oLagvYsp/fz3HQXiwHefu4jj5OtwO0/Hv81pebq/zeTeX3VtZ/xzK8WO5IVglGln3lXQkjxxL5spaE2qCVYLBjdmQZ6Q2UhJfSUcIKrKvCqu51Xw3B8X8DFHPuJpYNa0WBINtVvPx8juVoZymMg27YVykxfOwyO7Mnbgjd@xO3aXABChQAQtcADsyoBHQfxRzoFOEvrIIXYkicIS7WGOocESzOJBSamQlv1NkMIvjVMWod4AZkRp1uCoDJuDku7QTTXJoqPOibPxAMAQecGXQYxJxA5EWUWbVfjdmThqDyUKWsillk2g/S8KLol3LKn20eDNMC61xiPld1VEq0kXRE7QgLXjXpoQmjXwfdb3PDERGwcnRALO2KnpnwjPtt0/@By7fp/X35X3ZfgK@6XV5Xq228z8 "JavaScript (V8) – Try It Online"
#2: Post edited by user avatar --Hyde‭ · 2024-05-25T08:14:03Z (6 months ago)
move Google Sheets formula to its own answer
  • # JavaScript (V8), 149 bytes
  • ```
  • t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/)
  • ```
  • Simple regex. Returns `null` on valid strings.
  • [Try it online!][TIO-lwklk18h]
  • [JavaScript (V8)]: https://v8.dev/
  • [TIO-lwklk18h]: https://tio.run/##RVI9b0IxDNz7K94GSC2slRBd7CWSvUaWnhgQgn6oLagvYsp/fz3HQXiwHefu4jj5OtwO0/Hv81pebq/zeTeX3VtZ/xzK8WO5IVglGln3lXQkjxxL5spaE2qCVYLBjdmQZ6Q2UhJfSUcIKrKvCqu51Xw3B8X8DFHPuJpYNa0WBINtVvPx8juVoZymMg27YVykxfOwyO7Mnbgjd@xO3aXABChQAQtcADsyoBHQfxRzoFOEvrIIXYkicIS7WGOocESzOJBSamQlv1NkMIvjVMWod4AZkRp1uCoDJuDku7QTTXJoqPOibPxAMAQecGXQYxJxA5EWUWbVfjdmThqDyUKWsillk2g/S8KLol3LKn20eDNMC61xiPld1VEq0kXRE7QgLXjXpoQmjXwfdb3PDERGwcnRALO2KnpnwjPtt0/@By7fp/X35X3ZfgK@6XV5Xq228z8 "JavaScript (V8) – Try It Online"
  • The same as a Google Sheets formula (**155 bytes**):
  • ```
  • =regexextract(A1,"CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX")
  • ```
  • Returns an error on valid strings.
  • # JavaScript (V8), 149 bytes
  • ```
  • t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/)
  • ```
  • Simple regex. Returns `null` on valid strings.
  • [Try it online!][TIO-lwklk18h]
  • [JavaScript (V8)]: https://v8.dev/
  • [TIO-lwklk18h]: https://tio.run/##RVI9b0IxDNz7K94GSC2slRBd7CWSvUaWnhgQgn6oLagvYsp/fz3HQXiwHefu4jj5OtwO0/Hv81pebq/zeTeX3VtZ/xzK8WO5IVglGln3lXQkjxxL5spaE2qCVYLBjdmQZ6Q2UhJfSUcIKrKvCqu51Xw3B8X8DFHPuJpYNa0WBINtVvPx8juVoZymMg27YVykxfOwyO7Mnbgjd@xO3aXABChQAQtcADsyoBHQfxRzoFOEvrIIXYkicIS7WGOocESzOJBSamQlv1NkMIvjVMWod4AZkRp1uCoDJuDku7QTTXJoqPOibPxAMAQecGXQYxJxA5EWUWbVfjdmThqDyUKWsillk2g/S8KLol3LKn20eDNMC61xiPld1VEq0kXRE7QgLXjXpoQmjXwfdb3PDERGwcnRALO2KnpnwjPtt0/@By7fp/X35X3ZfgK@6XV5Xq228z8 "JavaScript (V8) – Try It Online"
#1: Initial revision by user avatar --Hyde‭ · 2024-05-24T11:32:36Z (6 months ago)
# JavaScript (V8), 149 bytes


```
t=>t.match(/CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX/)
```

Simple regex. Returns `null` on valid strings.

[Try it online!][TIO-lwklk18h]

[JavaScript (V8)]: https://v8.dev/
[TIO-lwklk18h]: https://tio.run/##RVI9b0IxDNz7K94GSC2slRBd7CWSvUaWnhgQgn6oLagvYsp/fz3HQXiwHefu4jj5OtwO0/Hv81pebq/zeTeX3VtZ/xzK8WO5IVglGln3lXQkjxxL5spaE2qCVYLBjdmQZ6Q2UhJfSUcIKrKvCqu51Xw3B8X8DFHPuJpYNa0WBINtVvPx8juVoZymMg27YVykxfOwyO7Mnbgjd@xO3aXABChQAQtcADsyoBHQfxRzoFOEvrIIXYkicIS7WGOocESzOJBSamQlv1NkMIvjVMWod4AZkRp1uCoDJuDku7QTTXJoqPOibPxAMAQecGXQYxJxA5EWUWbVfjdmThqDyUKWsillk2g/S8KLol3LKn20eDNMC61xiPld1VEq0kXRE7QgLXjXpoQmjXwfdb3PDERGwcnRALO2KnpnwjPtt0/@By7fp/X35X3ZfgK@6XV5Xq228z8 "JavaScript (V8) – Try It Online"

The same as a Google Sheets formula (**155 bytes**):

```
=regexextract(A1,"CCCC|CC[DM]|CM[CDM]|DC[DM]|DD|DM|I[CDLM]|IIII|II[VX]|IVI|IX[CILVX]|L[CDLM]|LX[CL]|MMMM|V[CDLMVX]|VI[VX]|XCC[DLMX]|XD|XLX|XM|XX[CL]|XXXX")
```

Returns an error on valid strings.