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 5 of 5

Thread: regex

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts

    regex

    Should alert '' twice , instead alerts original text
    Code:
          text = 'p18=100';
          text = text.replace("(^|&)p100=18.*?(&|$)","")
          alert(text);
          text = text.replace(/(^|&)p100=18.*?(&|$)/g,"")
          alert(text);
    tested regex on online tester and it should be OK.

    ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,108
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Quote Originally Posted by BubikolRamios View Post
    Should alert '' twice , instead alerts original text
    Code:
          text = 'p18=100';
          text = text.replace("(^|&)p100=18.*?(&|$)","")
          alert(text);
          text = text.replace(/(^|&)p100=18.*?(&|$)/g,"")
          alert(text);
    tested regex on online tester and it should be OK.

    ?
    Your match to replace with does not equal the original.
    Code:
    <script type="text/javascript">
    
          var text = 'p18=100';  
          var otxt = text;
          var txt = /^p18=100\.*/;
             text = text.replace(txt,"")
          alert('Old: '+otxt+'\nNew: '+text);
          
    </script>

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,154
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    Code:
    <script type="text/javascript">
    text = 'p100=18';
    text = text.replace(/(^|&)p100=18.*?(&|$)/ ,"")
    alert (text);
    text = text.replace(/(^|&)p100=18.*?(&|$)/g,"")
    alert (text);     
    </script>
    Note that ^ and $ are literal characters in your regex - not start and end of string. So if you really want these they must be escaped.

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.
    Last edited by Philip M; 12-20-2010 at 09:13 AM.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,108
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by Philip M View Post
    ...

    Note that ^ and $ are literal characters in your regex - not start and end of string. So if you really want these they must be escaped.

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.
    Nice catch ... I was in a PERL mindset.

  • #5
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by Philip M View Post
    [CODE]
    Note that ^ and $ are literal characters in your regex - not start and end of string. So if you really want these they must be escaped.
    Yeah, I realy want those.
    It took mi some time to see why it does not match.
    if I would not been told to, probably wouldnt spot it at all.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

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