From: Vicente Bosch Date: 2012-09-11T23:44:51+09:00 Subject: String iterate through regex matches with possition --485b397dce039c120404c96e1dcc Content-Type: text/plain; charset=UTF-8 Hi, First of all sorry if this a duplicate question ( I have scanned through the last answers regarding regex and didn't get any ideas ). I am scanning a string in order to detect correctly formed "records" in it. A correct record is a "SP" mark followed by "NL" marks (0 or more ) and an ending "EP" mark. If we find an two EPs without a SP in the middle, two SPs without a EP in the middle, or a mark other than "NL" in between the SP and EP marks the record is invalid. "BS HD SP SP EP SP NL EP EP FT BS" We have the following records: - SP EP - SP NL EP I scan through them and I am able to retrieve them with: string.scan(/(SP)\s((?:NL\s)*)(EP)/) But I am not getting the start and end position of the match inside the string ( which I need to retrive data from another place). Is there any way to scan the string for matches where I get the index possition ? Maybe I should not even be using scan ? Thanks for your help and time. Regards, V. --485b397dce039c120404c96e1dcc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,

First of all sorry if this a duplicate question ( I = have scanned through the last answers regarding regex and didn't get an= y ideas ).

I am scanning a string in order to dete= ct correctly formed "records" in it. A correct record is a "= SP" mark followed by "NL" marks (0 or more ) and an ending &= quot;EP" mark.=C2=A0
If we find an two EPs without a SP in the middle, two SPs without a EP= in the middle, or a mark other than "NL" in between the SP and E= P marks the record is invalid.

"BS HD SP SP E= P SP NL EP EP FT BS"=C2=A0

We have the following records:

- SP EP

- SP NL EP

=C2= =A0I scan through them and I am able to retrieve them with: =C2=A0

string.scan(/(SP)\s((?:NL\s)*)(EP)/)

But I am= not getting the start and end=C2=A0position=C2=A0of the match inside the s= tring ( which I need to retrive data from another place).=C2=A0
<= br>
Is there any way to scan the string for matches where I get the index possi= tion ?

Maybe I should not even be using scan ?=C2= =A0

Thanks for your help and time.

<= /div>
Regards,
V.=C2=A0
--485b397dce039c120404c96e1dcc--