File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed
docs/acton-guide/src/stdlib Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 33## Unreleased
44
55### Added
6+ - ` re.match() ` now accepts an optional ` start_pos ` to begin scanning at an offset.
67- Add ` acton doc ` command for generating documentation [ #2292 ]
78 - Supports multiple output formats (text, markdown, HTML)
89 - Default is to open browser into HTML docs when window environment is
Original file line number Diff line number Diff line change @@ -43,11 +43,12 @@ class Match:
4343def _match(pattern: str, string: str, start_pos: int) -> ?Match:
4444 NotImplemented
4545
46- def match(pattern: str, string: str) -> ?Match:
46+ def match(pattern: str, string: str, start_pos: int=0 ) -> ?Match:
4747 """Scan through string looking for a match to the pattern, returning
48- a match object, or None if no match was found.
48+ a match object, or None if no match was found. start_pos sets the
49+ index to begin scanning at.
4950 """
50- return _match(pattern, string, 0 )
51+ return _match(pattern, string, start_pos )
5152
5253def matches(pattern: str, string: str) -> list[Match]:
5354 """Find all non-overlapping matches in string
Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ actor main(env):
1212 env.exit(0 )
1313```
1414
15+ ` re.match ` also accepts an optional ` start_pos ` to begin scanning at a
16+ specific index (defaults to 0).
17+
1518Output:
1619``` sh
1720Got a match: foobar
1821```
19-
Original file line number Diff line number Diff line change @@ -92,6 +92,25 @@ def _test_match_positions():
9292 # Also verify the substring matches what we expect
9393 testing.assertEqual(m.string[m.start_pos:m.end_pos], "def")
9494
95+ def _test_match_start_pos():
96+ """Test that start_pos controls where the search begins."""
97+ s = "def def"
98+
99+ m1 = re.match("def", s)
100+ testing.assertNotNone(m1, "Should have matched first 'def'")
101+ if m1 is not None:
102+ testing.assertEqual(m1.start_pos, 0)
103+ testing.assertEqual(m1.end_pos, 3)
104+
105+ m2 = re.match("def", s, start_pos=4)
106+ testing.assertNotNone(m2, "Should have matched second 'def' starting at index 4")
107+ if m2 is not None:
108+ testing.assertEqual(m2.start_pos, 4)
109+ testing.assertEqual(m2.end_pos, 7)
110+
111+ m3 = re.match("def", s, start_pos=5)
112+ testing.assertNone(m3, "start_pos should skip earlier matches")
113+
95114def _test_split_no_match():
96115 """Split: pattern does not match anywhere"""
97116 res = re.split("xyz", "abc def ghi")
You can’t perform that action at this time.
0 commit comments