Home > Blockchain >  Regular Expression, check of substring at position
Regular Expression, check of substring at position

Time:03-15

I have these 2 strings:

  • 00000000000008165736
  • RF77706578000000000543278

I need a regular expression that checks at position 15 that the next 3 characters are 657 or at position 6 the next 3 character are 657

This needs to be one regular expression that matches both strings.

I 've been working on something like this ^.{15}(.{3})|^.{6}(.{3}) but I can't straight it out.

CodePudding user response:

^(.{6}|.{15})657

For a demo you can see here: https://regex101.com/r/Aj0qG8/1

CodePudding user response:

You may use the following regex pattern:

^(?:.{6}657|.{15}657)

Demo

This regex says to match:

^   from the start of the string
(?:
    .{6}657   657 starting at the 7th character
    |         OR
    .{15}657  657 starting at the 16th character
)
  • Related