Kyle Miller 1 Posted April 9, 2023 I am searching for a number pattern in a string, e.g. 123-12 or 123-1234. 123-13-123, 123-123-1234, 123-12x are not a matches. This pattern, \d+-\d+(?=[\s$]) , works except when the number is the only thing in the string, i.e. '123-12' with no spaces following. Add a space on the end, and RegEx works. This was tested in Delphi XE. What am I missing? Share this post Link to post
Brian Evans 105 Posted April 9, 2023 (edited) Outside a set $ matches a position not a character and within a set it matches the character $. One option is to use a capture group with |. So this pattern: \d+-\d+(\s|$) Edited April 9, 2023 by Brian Evans 1 Share this post Link to post
Kyle Miller 1 Posted April 9, 2023 Ah. I was trying to say a space or end of line was allowed. Your capture group works better. Thank you. I made small modification for punctuation because "122-22." or "122-22," or the like is acceptable. Share this post Link to post