#P4535. Regular Expression Matching Positions
Regular Expression Matching Positions
Regular Expression Matching Positions
Your task is to process the given input that consists of a regular expression and a text string, and output all starting positions where the regex pattern matches the text.
The input includes:
- A valid regular expression (according to standard regex rules).
- A text string which can be very long.
You must find all non-overlapping matches of the given pattern in the text. For each match, output its starting index (0-indexed) in a single line separated by a space. If there is no match, print -1
.
Note: If a pattern matches an empty string, to avoid infinite loops, consider advancing the search by one character.
Mathematically, if a match occurs that starts at index i and ends at j (with j = i + k, k ≥ 0), then the output should contain i. That is, output the solution set: \[ \{ i \mid \text{the substring starting at } i \text{ matches the regular expression} \}\]
inputFormat
The input consists of two lines:
- The first line contains a valid regular expression.
- The second line contains the text string.
outputFormat
If there are one or more matches, output the starting indices (0-indexed) of each match separated by a space in one line. If no match is found, output -1
.
sample
ab
abab
0 2