![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Simple Regular Expression Hello Group, This string matches although the number has 5 digits. What's wrong? $string = "NYC-CC-35225" $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" $string -match $expression |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Simple Regular Expression Technically, it is correct. Looking just at the last bit, you asked it to match 4 digits, and there were 4 digits. There was also another digit, but that was not part of the match. If you want the entire string to match from beginning to end, try: $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada https://mvp.support.microsoft.com/profile/Tom.Moreau "BJ" <post@xxxxxx> wrote in message news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx Hello Group, This string matches although the number has 5 digits. What's wrong? $string = "NYC-CC-35225" $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" $string -match $expression |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Simple Regular Expression Thank you very much, it works! It will take a long time to get used to regular expressions, especially for a newbie like myself....... On 30 Jan., 20:32, "Tom Moreau" <t...@xxxxxx> wrote: Quote: > Technically, it is correct. * Looking just at the last bit, you asked itto > match 4 digits, and there were 4 digits. *There was also another digit, but > that was not part of the match. *If you want the entire string to match from > beginning to end, try: > > $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" > > -- > * *Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON * Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau > > "BJ" <p...@xxxxxx> wrote in message > > news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx > Hello Group, > > This string matches although the number has 5 digits. > What's wrong? > > $string = "NYC-CC-35225" > $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" > > $string -match $expression |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Simple Regular Expression The problem for me is that I am a Perl jock and the syntax for Perl vs. MS regular expressions is somewhat different. I was looking for negative and positive look-ahead and look-behind and couldn't come up with what I wanted. -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada https://mvp.support.microsoft.com/profile/Tom.Moreau "BJ" <post@xxxxxx> wrote in message news:026e669a-dc07-4fa1-b586-7a99bcff4944@xxxxxx Thank you very much, it works! It will take a long time to get used to regular expressions, especially for a newbie like myself....... On 30 Jan., 20:32, "Tom Moreau" <t...@xxxxxx> wrote: Quote: > Technically, it is correct. Looking just at the last bit, you asked it to > match 4 digits, and there were 4 digits. There was also another digit, but > that was not part of the match. If you want the entire string to match Quote: > beginning to end, try: > > $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau > > "BJ" <p...@xxxxxx> wrote in message > > news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx > Hello Group, > > This string matches although the number has 5 digits. > What's wrong? > > $string = "NYC-CC-35225" > $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" > > $string -match $expression |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Simple Regular Expression Here's the .NET syntax ![]() (?= ...) Positive lookahead (?! ...) Negative lookahead (?<= ...) Positive lookbehind (?<! ...) Negative lookbehind ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > The problem for me is that I am a Perl jock and the syntax for Perl > vs. MS regular expressions is somewhat different. I was looking for > negative and positive look-ahead and look-behind and couldn't come up > with what I wanted. > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > https://mvp.support.microsoft.com/profile/Tom.Moreau > "BJ" <post@xxxxxx> wrote in message > news:026e669a-dc07-4fa1-b586-7a99bcff4944@xxxxxx > ... > Thank you very much, it works! > It will take a long time to get used to regular expressions, > especially for a newbie like myself....... > On 30 Jan., 20:32, "Tom Moreau" <t...@xxxxxx> wrote: > Quote: >> Technically, it is correct. Looking just at the last bit, you asked >> it to match 4 digits, and there were 4 digits. There was also another >> digit, but that was not part of the match. If you want the entire >> string to match >> > Quote: >> beginning to end, try: >> >> $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" >> >> -- >> Tom >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON >> Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau >> "BJ" <p...@xxxxxx> wrote in message >> >> news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx >> ... Hello Group, >> >> This string matches although the number has 5 digits. What's wrong? >> >> $string = "NYC-CC-35225" >> $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" >> $string -match $expression >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Simple Regular Expression Thanx. Looks like it's the same as Perl. Have you got a link to this at the MSDN site? -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada https://mvp.support.microsoft.com/profile/Tom.Moreau "Shay Levi" <no@xxxxxx> wrote in message news:8766a9441c84f8ca31a6cfa302f8@xxxxxx Here's the .NET syntax ![]() (?= ...) Positive lookahead (?! ...) Negative lookahead (?<= ...) Positive lookbehind (?<! ...) Negative lookbehind ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > The problem for me is that I am a Perl jock and the syntax for Perl > vs. MS regular expressions is somewhat different. I was looking for > negative and positive look-ahead and look-behind and couldn't come up > with what I wanted. > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > https://mvp.support.microsoft.com/profile/Tom.Moreau > "BJ" <post@xxxxxx> wrote in message > news:026e669a-dc07-4fa1-b586-7a99bcff4944@xxxxxx > ... > Thank you very much, it works! > It will take a long time to get used to regular expressions, > especially for a newbie like myself....... > On 30 Jan., 20:32, "Tom Moreau" <t...@xxxxxx> wrote: > Quote: >> Technically, it is correct. Looking just at the last bit, you asked >> it to match 4 digits, and there were 4 digits. There was also another >> digit, but that was not part of the match. If you want the entire >> string to match >> > Quote: >> beginning to end, try: >> >> $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" >> >> -- >> Tom >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON >> Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau >> "BJ" <p...@xxxxxx> wrote in message >> >> news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx >> ... Hello Group, >> >> This string matches although the number has 5 digits. What's wrong? >> >> $string = "NYC-CC-35225" >> $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" >> $string -match $expression >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Simple Regular Expression http://msdn2.microsoft.com/en-us/library/ms972966.aspx ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > Thanx. Looks like it's the same as Perl. Have you got a link to this > at the MSDN site? > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > https://mvp.support.microsoft.com/profile/Tom.Moreau > "Shay Levi" <no@xxxxxx> wrote in message > news:8766a9441c84f8ca31a6cfa302f8@xxxxxx > Here's the .NET syntax ![]() > > (?= ...) Positive lookahead > (?! ...) Negative lookahead > (?<= ...) Positive lookbehind > (?<! ...) Negative lookbehind > ----- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com Quote: >> The problem for me is that I am a Perl jock and the syntax for Perl >> vs. MS regular expressions is somewhat different. I was looking for >> negative and positive look-ahead and look-behind and couldn't come up >> with what I wanted. >> >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON Canada >> https://mvp.support.microsoft.com/profile/Tom.Moreau >> "BJ" <post@xxxxxx> wrote in message >> news:026e669a-dc07-4fa1-b586-7a99bcff4944@xxxxxx >> m >> ... >> Thank you very much, it works! >> It will take a long time to get used to regular expressions, >> especially for a newbie like myself....... >> On 30 Jan., 20:32, "Tom Moreau" <t...@xxxxxx> wrote: Quote: >>> Technically, it is correct. Looking just at the last bit, you asked >>> it to match 4 digits, and there were 4 digits. There was also >>> another digit, but that was not part of the match. If you want the >>> entire string to match >>> >> Quote: >>> beginning to end, try: >>> >>> $expression = "^[a-z]{3}\-[a-z]{2}\-[0-9]{4}$" >>> >>> -- >>> Tom >>> ---------------------------------------------------- >>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >>> SQL Server MVP >>> Toronto, ON >>> Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau >>> "BJ" <p...@xxxxxx> wrote in message >>> news:1b523a23-05d3-4dc0-9285-9a4f7ad00eb7@xxxxxx >>> m ... Hello Group, >>> >>> This string matches although the number has 5 digits. What's wrong? >>> >>> $string = "NYC-CC-35225" >>> $expression = "[a-z]{3}\-[a-z]{2}\-[0-9]{4}" >>> $string -match $expression |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Regular Expression help C# | .NET General | |||
| Regular Expression for ../ | .NET General | |||
| Help with a regular expression | VB Script | |||
| regular expression help | VB Script | |||
| simple regular expression | PowerShell | |||