On Which Line Number Was the Regex Match Found?

前端 未结 3 717
情深已故
情深已故 2021-01-25 08:55

I would like to search a .java file using Regular Expressions and I wonder if there is a way to detect one what lines in the file the matches are found.

Fo

3条回答
  •  爱一瞬间的悲伤
    2021-01-25 09:28

    There are no methods in Java that will do it for you. You must read the file line-by-line and check for a match on each line. You can keep an index of the lines as you read them and do whatever you want with that index when a match is found.

提交回复
热议问题