If regexmatches true

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
hermhart
Posts: 257
Joined: 13 Jan 2015 18:41

If regexmatches true

Post by hermhart »

I am trying to do an IF statement to see if a regexmatches, and if it does to set a pattern. I'm having an issue trying to:
  • Understand why, without quotes around the $file = 1234567_-.txt it seems to drop the period before "txt" in the value for $file.
  • And not sure why it seems that the first line of the IF statement doesn't match, do I have the regex pattern wrong?

Code: Select all

 $file = 1234567_-.txt;

 if (regexmatches($file, "(.*)_([0-9a-zA-Z\-]*)(\.)(txt)$") == "1") {
        $fRegExPat = "(.*)_([0-9a-zA-Z\-]*)(\.)(txt)$";
    }
    else {
        $fRegExPat = "No match";
    }

 echo $fRegExPat;
Windows 11 Pro; 100% scaling

jupe
Posts: 3570
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: If regexmatches true

Post by jupe »

So I would assume since you are trying to use regexmatches() you would have read the help for that command, where it is documented that the return from regexmatches is the list of matches not 1 or 0, also all strings need quoting so without the quotes the period is used to join the strings instead.

hermhart
Posts: 257
Joined: 13 Jan 2015 18:41

Re: If regexmatches true

Post by hermhart »

Thank you. I will look at that a bit deeper. I think I was getting too frustrated when I couldn't get things to work.
Windows 11 Pro; 100% scaling

Post Reply