Author Topic: Regular expressions and word wrapping  (Read 179 times)

zpaolo11x

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
    • My deviantart page
Regular expressions and word wrapping
« on: August 21, 2019, 05:39:53 AM »
In my experiments regarding word wrap I tried to use a regex. The simplest incarnation would be a regular expression that matches, say, 10 characters at a time. the code I used is:

Code: [Select]
local es = "(.{10})"
local cs = "Contrary to popular belief Lorem Ipsum is not simply random text"
local r = regexp(es)
local rs = r.capture(cs)

if (rs) {
    foreach (index, value in rs) {
        print(format("Match %02d: %s", index + 1, cs.slice(value.begin, value.end))+"\n")
    }
}

but the output is just:

Code: [Select]
Match 01: Contrary t
Match 02: Contrary t

It seams that after the first match it doesn't create other matches... any idea?