Skip to content

Instantly share code, notes, and snippets.

@zmajstor
Created May 8, 2014 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmajstor/f30a0e46017cfa3b1ca2 to your computer and use it in GitHub Desktop.
Save zmajstor/f30a0e46017cfa3b1ca2 to your computer and use it in GitHub Desktop.
build string based on input strings and regex
# input parameters (from LDAP or device attributes SERIAL, UDID) ...
param1 = "abcdefgh12345678"
param2 = "qwertyui09876543"
param3 = "asdfghjkl@zxcvbnml"
# take first 5 non-whitespace character
regex1 = /^\S{5}/
# take last 4 non-whitespace character
regex2 = /\S{4}$/
# take all non-whitespace characters after @
regex3 = /(?<=@)\S+/
print "cn = "
puts "#{param1[regex1]}-#{param2[regex2]}.#{param3[regex3]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment