firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.26k stars 199 forks source link

Match Info to include Line Numbers #1989

Closed KareemAaron closed 1 year ago

KareemAaron commented 1 year ago

Feature

The match info section currently includes:

I looked in settings, but couldn't find an option to enable line of match.

It would be awesome to know on what line the match occurred.

image

working-name commented 1 year ago

Hi @KareemAaron,

Quick tip: if you click Match 2 in the match information sidebar it should jump to the line it matched. I realize it's probably not as useful if you were trying to export a list of matches and their line numbers. At that point it might be worth creating a little script for yourself, but I digress.

Will this work at all?

KareemAaron commented 1 year ago

I'm aware of the ability to click a match to jump to its location. I have 162 matches, so it would be very time intensive to click each match simply to see what line I land on. My reasoning for the line number is actually really simple: I want to see if I have one or more matches per line.

working-name commented 1 year ago

Yeah, I get it. In the meantime maybe this idea might help some: https://regex101.com/r/rGCuK5/1 (using ^ beginning of line and $ end of line when /m flag is on). An indirect second "match" count where match can be either the same text as first \1 or some text that matches the same pattern \g<1> (recursion) https://regex101.com/r/rGCuK5/2.

firasdib commented 1 year ago

Line numbers aren't really a construct when it comes to regex matching. The engine will not return which line something happened at, only which position. We could try to extrapolate from this, by counting newlines prior to the position, but it's not ideal, as it will consume quite some resources.