>lcString = 'abc1234567890123456fd' > >loRegExp = CREATEOBJECT("VBScript.Regexp") > >loRegExp.PATTERN = "\D\d{16}\D*" && search for non digit following by 16 digits > >loRegExp.IgnoreCase = .T. > >loRegExp.GLOBAL = .T. > >loMatches = loRegExp.Execute(lcString) > >lnMatches = loMatches.Count && Number of matches > >FOR lnMatch = 0 TO (lnMatches - 1) > > ?loMatches.Item(lnMatch).FirstIndex && Start position > ?loMatches.Item(lnMatch).value > >ENDFOR >>
loRegExp = CREATEOBJECT("VBScript.Regexp") loRegExp.PATTERN = "(\D)(\d{16})(\D|$)" && search for non digit following by 16 digits loRegExp.IgnoreCase = .T. && In this case, IgnoreCase = false is sufficient loRegExp.GLOBAL = .T. lcString = 'abc1234567890123456fd' lcString = 'abc1234567890123456' ?m.loRegExp.Test(m.lcString)(1) you can use replace() - see below - see also page 19 first row http://www.atoutfox.org/modules/articles/pdf/0000000748.pdf
&& With replace() && if is optional if( m.loRegExp.Test(m.lcString) ) ? 'old: ', m.lcString lcString = m.loRegExp.Replace(m.lcString, '$1$2X$3') ? 'new: ', m.lcString endif(2) Using Execute() is also possible and it gives you finer control
&& or with Execute() lcString = 'abc1234567890123456' matchesObj = m.loRegExp.Execute(m.lcString) ? 'old: ', m.lcString for i = m.matchesObj.Count - 1 to 0 step -1 match = m.matchesObj.item(m.i) ?match.Submatches.Count ?match.Submatches[0] ?match.Submatches[1] ?match.Submatches[2] s = m.match.Submatches[0] + m.match.Submatches[1] + 'X' + match.Submatches[2] lcString = stuff(m.lcString, m.match.FirstIndex+1, m.match.Length, m.s) endfor ? 'new: ', m.lcString