In brief, I am puzzled as to why ~^[0-9]*?\|[0-9]*?\|.*?\|.*?\..*?\|2\|[0-9]\|.*?$~m matches 1362526368|5|Corinne E. Fischer|fischer.jpg|3|3||416-864-5320|1|2|3|4|5
Note the |3| after fischer.jpg when the pattern clearly has a \|2\| in that location. Now I understand that it must be the numbers at the end that are messing with the match but I don't really know how to fix it (the numbers at the end don't have to be numbers but can be any characters). This shouldn't be an issue later when I fill in proper data but I just want to know where I'm going wrong for future reference and for my peace of mind.

If you want I can include my original data as well as my complete pattern (I made this one just to test my theory).

Thank you for your time, evidently I'm not very good with regex.

Recommended Answers

All 2 Replies

Nevermind, it seems to be working now. I cleaned up my pattern ~^[0-9]*?\|[0-9]*?\|.*?\|.*?\.[^0-9]*?\|3\|[1-3]\|.*?\|.*?\|.*?\|.*?\|.*?\|.*?\|.*?$~m and it's working ok now. Still not sure what was wrong though...

the problem is because of wild card character that you have used.


here .* is a wild card which allows as many characters.
And it is returning true because |2| is there in test string.Remove that and you can see it will return false.
Be careful before using wild card .If using either limit characters or type of characters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.