RegEx Format Help

J

jp2msft

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)
 
A

Arne Vajhøj

jp2msft said:
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
 
J

jp2msft

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 said:
jp2msft said:
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
 
A

Arne Vajhøj

jp2msft said:
Arne Vajhøj said:
jp2msft said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top