Skip to content
turnspike

turnspike

"With our thoughts, we make the world."

  • about
  • tweets
  • github
  • contact

Tag: regex

regex: extract LDAP cn value from dn string

Regex snippet to extract the cn value from a dn string for LDAP:

Input:

cn=smit1057,ou=ACTIVE,ou=PEOPLE,o=DATA

Target Output:

smit1057

Regex:

/^cn=([^,]+)/$1/

Ruby:

def get_id_from_cname(cname:)
  match = /^cn=([^,]+)/.match(cname)
  return match[1] if match.is_a?(MatchData) && match.length > 0
  return false
end
turnspike Lab Notes Leave a comment December 4, 2017June 16, 2020 1 Minute

regex: attribute list to Ruby hash

Snippet to convert a list of attributes to a Ruby hash.

Input:

cn:ID
sn:Surname
fn:FirstName

Target output:

"cn" => "ID",
"sn" => "Surname",
"fn" => "FirstName",

Regex:

/(.+?)(?=\:):(.*$)/"$1" => "$2",/
turnspike Lab Notes Leave a comment December 4, 2017February 15, 2019 1 Minute

https://twitter.com/turnspiker

tags

adobe animate animation api byobu capybara debian design emacs fixme git heroku ios iot linux macos node okta oracle passenger philosophy plantuml pm projects rails regex rspec ruby security seo snippets tdd terminal tmux ubuntu vim webpacker zsh
Create a website or blog at WordPress.com
  • Subscribe Subscribed
    • turnspike
    • Already have a WordPress.com account? Log in now.
    • turnspike
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar