Skip to content
turnspike

turnspike

"With our thoughts, we make the world."

  • home
  • about
  • tweets
  • github
  • contact
  • home
  • 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
Tweets by turnspiker https://platform.twitter.com/widgets.js

tags

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