Ask Your Question
1

Substring match in a template

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

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
0

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

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

Comments

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

JoeDog gravatar imageJoeDog ( 2015-06-17 12:21:53 -0500 )edit
ramindk gravatar imageramindk ( 2015-06-17 14:23:05 -0500 )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

Stats

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

Seen: 1,748 times

Last updated: Jun 17 '15