Status
Not open for further replies.

examan345

Active Member
597
2012
104
0
I'm very new to javascript and i'm working on a small form to get the episode and season numbers from tv shows from release names ie I input Chicago Fire S01E11 480p HDTV x264-mSD and it only extracts S01E11 with regexp. But now I realized theres a small problem when the episodes are more than 2 digits long. I added if statements for if it fails to find the string S##E## to try S##E### and try all the combinations of 2 and 3 digit numbers until none of them work and it should add to the other textbox that you inputted wrong. Now it still only works for only 2 digits seasons and episodes and i dont know how to get it to figure out if a show has 3 digits episodes and/or seasons and use the alternative search. Here is where im at right now if anyone can help me get it to work would be highly appreciated.
Code:
<html>
<body>
<script type="text/javascript">
function filtering() 
{
  var str = document.form1.inTB.value;
  var filter1 = /\sS..E../;
  var filtered1 = str.match(filter1);
  if (filtered1.length == 0)
     {
     var filter1 = /\sS..E.../;
     var filtered1 = str.match(filter1);
     }
  if (filtered1.length == 0)
     {
     var filter1 = /\sS...E.../;
     var filtered1 = str.match(filter1);
     }
  if (filtered1.length == 0)
     {
     var filter1 = /\sS...E../;
     var filtered1 = str.match(filter1);
     }
  if (filtered1.length == 0)
     {
     var filter1 = /\sS..E.../;
     var filtered1 = str.match(filter1);
     }
  if (filtered1.length == 0)
     {
     var filtered1 = "You inputted wrong.";
     }
  document.form1.outTB.value = filtered1;
}
</script>

<form name="form1" method="post" action="">
<input name="inTB" type="text" id="inTB" value="" size="30">
<br>
<input type="button" name="" value="Filter" onClick="filtering();">
<br>
<input name="outTB" type="text" id="outTB" value="" size="30">
</form>
</body>
</html>
 
3 comments
thanks a lot for the help :) . I managed to figure it out myself by switching the regexs around and putting the 3 digit filters first. But it also worked perfectly with the second one
Code:
var filter1 = /S\d+E\d+/; 
//or
var filter1 = /S\d{1,2}E\d{1,3}/;
though the first one didnt work at all though that site was useful
mods can close the thread now
 
Status
Not open for further replies.
Back
Top