Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: RegExp question

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts

    RegExp question

    I have this string:

    this is my test <a href="yay.html">yay</a>

    and want to just match the part before the <a...:

    this is my test

    I can't figure out the regular expression for this. I've tried everything I can think of. It seems that it needs to do a non-greedy search on the first < it finds, but nothing works, like:

    ((.*<)?)

    Please help, thanks!

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Code:
    // this will give "this is my test "
    var result = 'this is my test <a href="yay.html">yay</a>'.match(/(.*)<a/)[1]

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Thank you! Looks like I was making it harder than it was.
    Last edited by Raphael; 09-22-2011 at 09:15 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •