Ask Your Question

Substring match in a template

asked 2015-06-17 10:12:37 -0600

JoeDog gravatar image

In a template is it possible to match the first letter of a variable?

psuedo code: <% if $hostname startswith('s') %>

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-17 11:17:46 -0600

ramindk gravatar image

Templates are standard Ruby which means you can use regex. No weird gyrations required.

<% if @hostname =~ /^s/ %>

You can test your regex using Rubular in case you're new to regex.

edit flag offensive delete link more


I'm familiar with regex so I greet this news with "awesome!" Thanks.

JoeDog gravatar imageJoeDog ( 2015-06-17 12:21:53 -0600 )edit
ramindk gravatar imageramindk ( 2015-06-17 14:23:05 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-06-17 10:12:37 -0600

Seen: 4,231 times

Last updated: Jun 17 '15