n1concepts Posted November 29, 2013 Share Posted November 29, 2013 I need to match only the files whose names start with a or z and end with a or z? I'm struggling with the reg to do this.... This what i have thus far but doesn't block to just the 1st letter 'a' or 'z' at beginning of a word or the last letter (same) 'a' or 'z'. Example: Regular Exp in 'ls' statement: ls [az]*[az$] Results: afkfz akfkea az za zdea zdkdkz However, the problem is [az$] also allowing: 'a', a 'z', or a '$'. Question: what am I doing wrong w/this regular expression? [az]*[az$] Should the $ sign be outside the bracket? That didn't work for me - any suggestions appreciated. Thx! Link to comment https://forums.phpfreaks.com/topic/284372-match-first-last-letters-a-or-z-only/ Share on other sites More sharing options...
kicken Posted November 29, 2013 Share Posted November 29, 2013 Question: what am I doing wrong w/this regular expression? [az]*[az$] That regex says 'A or Z, repeated any number of times, followed by A, Z or $' The regex you are looking for would be: ^[az].*[az]$ That regex says 'At the start of the string (^) look for either a or z ([az]), then any character (.) any number of times (*) followed by either a or z ([az]) then the end of the string ($)' Link to comment https://forums.phpfreaks.com/topic/284372-match-first-last-letters-a-or-z-only/#findComment-1460587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.