# Ruby regular expression issue matching

**URL:** <https://www.ruby-forum.com/t/ruby-regular-expression-issue-matching/158794>\
**Category:** Rails\
**Created:** [January 28, 2009, 2:12am UTC](https://www.ruby-forum.com/t/ruby-regular-expression-issue-matching/158794 "2009-01-28T02:12:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [January 28, 2009, 2:12am UTC](https://www.ruby-forum.com/t/ruby-regular-expression-issue-matching/158794/1 "2009-01-28T02:12:04Z")

</div>

I have something like this to match:

//s-#{slot}/p-#{port}/sts-#{sts}/

The problem is the variable STS if it is a 1 matches on 1,10,11,12,13  
and so on.

How do I get it to match only the value and nothing sles?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [January 28, 2009, 2:16am UTC](https://www.ruby-forum.com/t/ruby-regular-expression-issue-matching/158794/2 "2009-01-28T02:16:45Z")

</div>

> I have something like this to match:
> 
> //s-#{slot}/p-#{port}/sts-#{sts}/
> 
> The problem is the variable STS if it is a 1 matches on 1,10,11,12,13  
> and so on.
> 
> How do I get it to match only the value and nothing sles?

What follows the sts portion in your string? Is it something like  
“sts-123-foo” or “sts-123?foo” or something? You need to figure out  
what that character is and then add it to the regular expression. Or  
if it’s nothing and that’s the end of the line anchor it with ‘$’.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [January 28, 2009, 2:20am UTC](https://www.ruby-forum.com/t/ruby-regular-expression-issue-matching/158794/3 "2009-01-28T02:20:51Z")

</div>

doh. I do that in the rest of the expression, duh… Thanks. Mind  
fart I guess.
