Jump to content

Regular Expression, why it's wrong?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
I use simple syntacsis:
var regside = /(?<=_).+?(?=.png)/gi;
but the firebug returns me "invalid quantifier"?

#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Maybe this will help.
I'm not a pro in regex, and never understood the assertions, but your problem is here: ?<=
If you remove the lookbehind assertion firebug work... but I can't tell you why, or how to solve it... sorry

#3
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
look, or others, I need to select word "example" from this string: helloworld/something_example.ref, who can tell me how it must be with javascript?

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
regex: .*/.*_(.*)\..{3}
Assuming the extension is always 3 characters.

This regex matches a lot of things, but it's hard to write a good regex with just 1 example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
    function begin(){
        var input= 'helloworld/something_example.ref';
        var pattern= new RegExp('.*/.*_(.*)\..{3}');
        var matcher = pattern.exec(input);
        alert(matcher[1]);
    }
</script>
</head>
<body onload="javascript:begin()">
</body>
</html>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users