tags:

views:

53

answers:

4

I'm trying to come up with some regex to handle the # sign.

Example, #PRODUCT_143#

If the input were #PRODUCT_143, the regex #PRODUCT_(\d*$) matches and returns 143 as the match. But adding the # to the end of both the input and the regex causes it to break. what do I need to do here to get this to match?

+4  A: 

If you tried #PRODUCT_(\d*$)# it’s no surprise that it didn’t found a match. Since the $ already marks the end of the string and the # after it will never be matched.

So try this instead:

#PRODUCT_(\d*)#$
Gumbo
+1  A: 

It shouldn't break anything, maybe you've forgotten to move the $ in the regex, which means end of line? This regex should be fine:

#PRODUCT_(\d*)#$

(I'm not sure why you were capturing the end of line in your original regex).

Chad Birch
+1  A: 

Did you just forget to move the $ out of the parenthesis?

    ^#PRODUCT_([0-9]*)#$

Note the added ^ - may be it is not right for your input.

Daniel Brückner
+1  A: 

The $ probably matches as the end-of-line, so your extra # is confusing it:

#PRODUCT_(\d*)#$
EvanK