Click to See Complete Forum and Search --> : Can Regular Expression find the LAST occurence of a string?


moreta
01-22-2004, 03:21 PM
I need to find the position of the last "new line" in a string. Can this be done with a regular expression?

Thank you,
Moreta

Jeff Mott
01-22-2004, 08:09 PM
Don't need regular expressions. See lastIndexOf (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/string.html#1197005) method.

moreta
01-23-2004, 07:17 AM
Even better!

I don't work with Java Script very often, so am picking it up very slowly. Thank you for the direction, Jeff!

moreta
01-27-2004, 02:07 PM
This is what I used, but it doesn't work. I've reviewed the format, but I don't have an example using a new line... only a string. It's probably something really simple, but can't figure it out. Please help.

newline = testval.lastIndexOf(/"\n"/);I looked with and without " around \n, but couldn't get the \ to show up without the quotes. It does here, though. :confused:

Thank you,
Moreta

TheBearMay
01-27-2004, 02:11 PM
Try a double slash as in

newline = testval.lastIndexOf(/\\n/);

moreta
01-27-2004, 02:44 PM
Wasn't sure whether you were responding to my inability to display it in the PHP code sample or my inability to get it to work on my form. (I don't seem to have much ability.:rolleyes: )

Tried both, and it doesn't work for either situation. *sigh*

fredmv
01-27-2004, 02:53 PM
Originally posted by moreta
newline = testval.lastIndexOf(/"\n"/);Those should not be there...

moreta
01-27-2004, 03:00 PM
That did it! I knew it would be something obvious... if you knew what was obvious. :o

Fredmv, you are a genius.

Thank you!

fredmv
01-27-2004, 03:07 PM
You're very welcome. :D

Paul Jr
01-27-2004, 05:55 PM
Originally posted by moreta
Fredmv, you are a genius.
I will definitely second that. ;)

fredmv
01-27-2004, 06:00 PM
Quite flattering. Thanks guys. :p