1
string src = "portfolio1, portfolio2, portfolio20, portfolio300";

I'd like to match all strings that are of the pattern @"portfolio\d" where \d can be anywhere from 1-3 digits in length. I have read that the use of {a, b} should work, so I tried:

pattern = @"portfolio\d{1, 3}"

Searching in the string, src, for this pattern returned an empty set. the following patterns worked partially:

pattern = @"portfolio\d"
pattern = @"portfolio\d{1}"

3 Answers 3

9

Try this:

pattern = @"portfolio\d{1,3}"

Note that you should not put a space in between the brackets, as you have in your example. That's why it didn't work right.

0
0
String pattern = @"^(?:(?:portfolio\d{1,3})(?:\x2C\s)*)+$";

My attempt. Will match any number of comma-seperated portfolio\d{1,3}'s

1
  • I attempted this version out of curiosity and was unable to get it to work. There was never a match.
    – DonQuixote
    Jan 4, 2011 at 20:51
0

Running pattern "portfolio\d{1,3}" in Expresso, I get 4 matches on each of the portfolios. The space did it was the key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.