I have a problem when trying to use the result of match function in one new match.
This is the code:
<html>
<body>
<script type="text/javascript">
p="somelongtextmelongtextmelongtextmelongtext";
f1 = p.match(/some/g);
document.write(f1);
f2 = f1.match(/om/g);
document.write(f2);
</script>
</body>
</html>
The output is the word “some” when it must be “om”. I don’t understand this behavior and I need the output of f1 in a more complex situation.
Thanks in advance.
Are you sure that you pasted the exact same code that you’re testing?
I ask because
f1 = p.match(/some/g);returns an array of matches, and theArrayobject does not have a.matchmethod, sof1.match(/om/g);should throw an error.Anyways, the correct way to do this is: