Code Monkey home page Code Monkey logo

regexplained's Introduction

regexplained's People

Contributors

forbeslindesay avatar korvinszanto avatar leaverou avatar slevithan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

regexplained's Issues

Cursor doesn't show up at end of input

When _.supportsCh is false, the size of the input box is a couple of pixels too narrow to display the cursor when it's at the end of the input. This works fine if you navigate to the end using the keyboard, but if you just click there, you get no feedback.

Next/prev subpattern highlighting is not always accurate

Steps to reproduce: Enter a(a)(a) as the regex, and aaa as the target text. If you click "next subpattern", the first a in the text is incorrectly highlighted (it should be the second a). Click "next subpattern" again, and the first a remains highlighted (it should be the third a).

In this case, the problem stems from the fact that the backreference text can be found at multiple positions within the match. But it's possible to trigger the problem even without that, e.g., if a backreference should appear outside or partially outside of the match (thanks to lookahead), but the backreference text is also found within the match.

I know you're aware of this issue (since we previously talked about it), but IMO this is a very significant error for a tool that people will use to help them learn how regexes work.

As you know, JavaScript does not provide any way to accurately determine the starting position of subpattern matches for an arbitrary regex. But here are a couple potential ways to address this:

  1. Kill the 'next/previous subpattern' feature. The feature might not be worth saving, if it's inaccurate. Instead, perhaps you could list out the subpattern matches underneath or on the side of the target text.
  2. Use XHR and a programming language on the backend that allows you to determine subpattern match indexes. But then you’d run up against regex syntax and behavior differences between JavaScript and the backend regex flavor.

Add additional flags to keyboard shortcuts

Currently, only flags i and m have buttons in the UI, and flags i, m, y, u, s are supported via keyboard (Ctrl+<X>). This leaves out some flags that would be useful:

  • ES2015: flag y (sticky)
  • ES2015: flag u (unicode) - A button would be extra helpful since Ctrl+U triggers View Source.
  • ES2018: flag s (dotAll) - A button would be extra helpful since Ctrl+S triggers Save As.
  • ES2024: flag v (unicodeSets) - Can't be used together with u. A button would be helpful since Ctrl+V triggers Paste when an input is focused.

Aside: Flags d (ES2022) and g do not need to be toggleable, based on regexplained's current feature set. But it might be nice to allow turning flag g off via Ctrl+G on the keyboard even if there isn't a button for it in the UI.

Match highlighting doesn't work correctly with Japanese, etc.

The reason is match/subpattern highlighting expects every character to take the same width due to the use of a monospace font. However, the width of e.g. English characters doesn't apply to e.g. Japanese characters.

Example: try using /./ to match "片仮名" or "カタカナ".

There's probably some way to determine the actual width of matched text as rendered on the screen, which would be a part of fixing this.

Ctrl icon is not clear

The ^ character for control is not clear in the keyboard shortcuts, it required some hunting for me to figure out what the correct shortcuts were. Really cool project by the way.

Use alternative styling for \n and \r in subject text to indicate what's going on

Personally, I like the current magical handling of treating \n and \r in the subject text as literal LF and CR characters when searching for matches. However, it's non-obvious and only works for these two tokens (and not others supported by JS string literals like \\, \t, \v, \f, \b, \xFF, etc.). Therefore, most people are likely to initially expect that the regex \\n should match \n in the subject text (it doesn't).

(Aside: because of the current handling, there is no way to make a regex of \\n match anything. It won't match \n or \\n because \\ is not given the same magic handling in the subject text and therefore, for subject text \\n, the string is considered to be \ followed by a literal LF.)

Proposal: Apply special styling to \n and \r wherever they appear in the subject text, or alternatively, automatically convert them to the characters (U+240A) and (U+240D) as soon as they're typed in the subject text, then apply the magical match handling to and .

Match highlighting is broken when using \n or \r in subject text

Regexplained has special handling to treat "\r" and "\n" in the subject text as literal line feed and carriage return characters, but this handling is not working correctly.

Simple case (\n at start of the match):
Regex: \n
Subject text: \n
Result: The highlighted match is n, rather than \n.

With \n in middle of the match:
Regex: a\n
Subject text: a\n
Result: The highlighted match is a\ (incorrect), rather than a\n.

With backreference highlighting:
Regex: a(\n)
Subject text: a\n
Result: When highlighting the subpattern match, the overall match is shown as a\ (incorrect) and the subpattern match is shown as n (also incorrect, and shown outside of the overall match).

Other curious variations of this issue are possible, depending e.g. on whether \n or \r appear prior to a match, within a match but prior to a subpattern match, or within a subpattern match.

Error thrown and subpattern highlighting incorrect for non-participating groups

Example regex 1: a(b)(c)?
Example subject text 1: ab

Example regex 2: a(b)??
Example subject text 2: ab

Example regex 3: a|(b)
Example subject text 3: a

Current behavior: After using CTRL+down to advance subpattern matching to any capturing group that did not participate in the match, a JS error is thrown and the subpattern highlighting is incorrect.

Note that non-participating capturing groups are different than non-capturing groups and also different from groups that participate in the match but capture an empty string. That's why my examples used e.g. (c)? instead of (c?) (the latter will always participate in a successful match since the group itself is not optional).

Issue with whitespace at start or end of regex or text

Entering whitespace at the start or end of the regex or target text boxes does not cause the visible area to expand, and causes misalignment of the match highlighting.

I'm using Chrome 19. Let me know if more details are needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.