Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline substitution. #11

Closed
thorsummoner opened this issue Mar 31, 2014 · 9 comments
Closed

Newline substitution. #11

thorsummoner opened this issue Mar 31, 2014 · 9 comments

Comments

@thorsummoner
Copy link

It appears to currently be impossible to substitute a newline in the output. This might be a limitation of the code mirror framework in use.

@gskinner
Copy link
Owner

Right, we currently limit the Expression and Substitution fields to single line input. I've considered treating the Substitution value as a Javascript string, so you can use "\n" and other encoded characters. Open to feedback on this.

@thorsummoner
Copy link
Author

This is the originating request: http://stackoverflow.com/questions/22751526/regexr-com-substitution-with-new-line-feed I'm sure "peter-lee" on SO would love to talk to you more about it :)

@ghost
Copy link

ghost commented Apr 1, 2014

Great tool, but newline/tab substitution is the thing I stuck with.

@gskinner
Copy link
Owner

gskinner commented Apr 7, 2014

This also causes inconsistencies with the Share>Copy>Javascript workflow, because \n in the substitution is not decoded in RegExr, but is in JS.

To resolve this, I propose leveraging JSON.parse to decode escaped characters, and adding support to the SubstLexer to include highlighting / tooltips for them as well (ideally sharing code with the RegExLexer). I might take a stab at this when I have some time.

JSON.parse('"'+subst+'"'); // should decode all escaped chars.

@gskinner
Copy link
Owner

gskinner commented Apr 7, 2014

A little more info: This seems like a better solution, but requires appropriate error handling:

try { str = eval('"'+str.replace(/"/g,'\\"')+'"')); } catch(e) { /* etc */ }

@drogo007
Copy link

drogo007 commented Apr 8, 2014

The ability to clean up data (including newlines) and format text is the primary reason I tend to use regexr. I don't use regexp often enough to remember all the rules off the top of my head, so having regexr makes life very easy - except I can no longer insert special characters in the substituion. Which renders 2.0 almost completely broken for all my use cases.

@gskinner
Copy link
Owner

gskinner commented Apr 8, 2014

I just pushed a solution to this, supporting all JS escaped character formats, with appropriate errors and tooltips. This should be live in the next couple days.

@gskinner
Copy link
Owner

This is now active on the live site. I'd love any feedback you have.

@drogo007
Copy link

So a quick look this morning shows the new site now works like a charm for the kinds of things I tend to use Regexr for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants