This is probably a simple one but I’m very much a regex novice.
I’m looking to select the first line of every paragraph within a textarea on a page using a regular expression. After thinking I was there I have hit a problem.
Using http://gskinner.com/RegExr/ I came up with this:
/\r\r.*\r/g
but then I place that into my javascript and ran it on the page:
var headingsArr = document.getElementById("text").value.match(/\r\r.*\r/g);
and the array returns null.
Have I got the regular expression right and if so where am I going wrong when using it in my javascript!?
Thank you
This depends on what your newline characters are. I think you may better go for
I know in Regexr only a
\ris a newline. But in Windows normally\r\nis used, but under .*ix its normally only the\n.So
(?:\r\n|[\r\n])is an alternation, it tries at first to match\r\nif this is not found it matches either\ror\n.