Prior to now, my RegEx expression was as follows: RegEx pattern = new Regex(@"[BCX][P057]\d{5} \d{4} \d{2}"); That has worked, but now I have been asked to enable the ability for our expressions to include an underscore ('_') at each of the character positions. (This is an SQL Query, and the underscore acts as a wildcard for individual characters) Is there a nice way to modify my RegEx expression to include the underscore in a smart manner? (I'm not very good at creating RegEx expressions)
jp2msft wrote: > Prior to now, my RegEx expression was as follows: > > RegEx pattern = new Regex(@"[BCX][P057]\d{5} \d{4} \d{2}"); > > That has worked, but now I have been asked to enable the ability for our > expressions to include an underscore ('_') at each of the character > positions. (This is an SQL Query, and the underscore acts as a wildcard for > individual characters) > > Is there a nice way to modify my RegEx expression to include the underscore > in a smart manner? (I'm not very good at creating RegEx expressions) RegEx pattern = new Regex(@"[BCX_][P057_]\d{5} \d{4} \d{2}"); ? Or do you want underscore support for the digits as well ? Arne
Hi Arne, Yes, the digits are the part I'm having the most trouble with. Do I have to list each digit individually? "Arne Vajhøj" wrote: > jp2msft wrote: > > Prior to now, my RegEx expression was as follows: > > > > RegEx pattern = new Regex(@"[BCX][P057]\d{5} \d{4} \d{2}"); > > > > That has worked, but now I have been asked to enable the ability for our > > expressions to include an underscore ('_') at each of the character > > positions. (This is an SQL Query, and the underscore acts as a wildcard for > > individual characters) > > > > Is there a nice way to modify my RegEx expression to include the underscore > > in a smart manner? (I'm not very good at creating RegEx expressions) > > RegEx pattern = new Regex(@"[BCX_][P057_]\d{5} \d{4} \d{2}"); > > ? > > Or do you want underscore support for the digits as well ? > > Arne >
jp2msft wrote: > "Arne Vajhøj" wrote: >> jp2msft wrote: >>> Prior to now, my RegEx expression was as follows: >>> >>> RegEx pattern = new Regex(@"[BCX][P057]\d{5} \d{4} \d{2}"); >>> >>> That has worked, but now I have been asked to enable the ability for our >>> expressions to include an underscore ('_') at each of the character >>> positions. (This is an SQL Query, and the underscore acts as a wildcard for >>> individual characters) >>> >>> Is there a nice way to modify my RegEx expression to include the underscore >>> in a smart manner? (I'm not very good at creating RegEx expressions) >> RegEx pattern = new Regex(@"[BCX_][P057_]\d{5} \d{4} \d{2}"); >> >> ? >> >> Or do you want underscore support for the digits as well ? > Yes, the digits are the part I'm having the most trouble with. > > Do I have to list each digit individually? Just replace \d with [0-9_]. Arne
Works beautifully! Thank you, Sir! "Arne Vajhøj" wrote: > Just replace \d with [0-9_]. > > Arne >