johnnie
johnnie

Reputation: 2057

I need to check if a string contains a certain pattern using a regular expression

I have a string that is something like "Hello 9 you8 [C#587]" or "Hello 9 you8 [#587]"

I need to check if the string contains "[#numbers]" or "[letter#numbers]" using a regular expression in C#.

Please assist.

kind regards

In actual fact the "letter" part might be a word.

Please help as per update.

Thanks

Upvotes: 0

Views: 203

Answers (3)

John Woo
John Woo

Reputation: 263843

try this,

\[([A-Za-z]+)?#(\d)+\]

enter image description here

Upvotes: 1

theyetiman
theyetiman

Reputation: 8908

I belive you want something slightly different to @hsz's answer. His will only check the [letter#numbers] and not the [#numbers].

Try this:

\[[a-zA-Z]?#\d+\]

Upvotes: 0

hsz
hsz

Reputation: 152286

Try with following regex:

\[[a-zA-Z]?#\d+\]

Upvotes: 0

Related Questions