问题
So i have a string of numbers that i want to run a series of matching tests on.
i have a string of numbers that represent locations on a board. it looks something similar to '024578'
Then I test those strings for matches that represent three in a row. So testing for three in the same row is easy, because the numbers are consecutive. i just used the following code:
const rowsRegex = /([012]{3}|[345]{3}|[678]{3})/g;
now to check for three in the same column is proving difficult for my limited regex knowledge. i have three sets of non-consecutive numbers and don't know how to write the regex to match a string if all three numbers of a set are present in the string.
i tried variations on the idea i used for rows for the last hour or so on regex101, but havent had any success. i figure it would look something like the following:
const colsRegex = /([036]|[147]|[258])/g;
so with the string 013567, how can i match with the first set in colsRegex ?
thank you kindly for any and all help.
回答1:
Try this RegExp:
/^\d*0\d*3\d*6\d*$/
It should work, given it's copied and pasted from a comment you accepted as working.
来源:https://stackoverflow.com/questions/61538913/js-regex-to-match-a-string-with-a-set-of-3-non-concsecutive-characters