# Capbyara/Ruby/Regex

**URL:** <https://www.ruby-forum.com/t/capbyara-ruby-regex/253303>\
**Category:** Development\
**Tags:** cucumber, capybara\
**Created:** [November 6, 2019, 11:41am UTC](https://www.ruby-forum.com/t/capbyara-ruby-regex/253303 "2019-11-06T11:41:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterbonney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f9b8f/32.png) [@peterbonney](https://www.ruby-forum.com/u/peterbonney)\
**Post date:** [November 6, 2019, 11:41am UTC](https://www.ruby-forum.com/t/capbyara-ruby-regex/253303/1 "2019-11-06T11:41:08Z")

</div>

Hi,  
Firstly, thanks for the add 🙂

Secondly - I’m self-taught in Ruby/Selenium/Capybara/Regex so still trying to get my head around it all!

I’m hoping someone might be able to help me with my automated test.  
I’m using Capybara/Cucumber and the website under test has a CMS, when a user adds a component in the CMS the component is assigned an auto-generated class (eg “StyledTabsSection-dk9iyv-4 gkLKye”) the format is the same, so I have a regex that splits the class into 3 groups - `^(Styled)(\w*)(-\S*\s\S*)$`

What I’m not sure about is how I write the ruby/Capybara DSL to expect the class to contain the 2nd group in my regex

I’ve found a code snippet online that I think will be a good start:

> - m = “John 31”.match /\w+ (\d+)/
> - m[1]

I’m guessing I can do something like:

> module = displayed\_module.match “^(Styled)(\w\*)(-\S\*\s\S\*)$”  
> module[2]

> Then(“I can see the {displayed\_module} module on the page”) do |displayed\_module|  
> page.find\_by\_class(module[2]).tag\_name  
> end

But how do I write expect page.class to contain(module[2])?

Thanks in advance

Have a nice day 😄
