Created
March 9, 2017 20:59
-
-
Save wolftrax5/015536b6502486c8dc13e59c030f992e to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rositi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<textarea name="text" id="text" cols="30" rows="10"></textarea> | |
<button id="button">Convert</button> | |
<div id="result" style="display:block; width: 300px;height:100px; background: white;"> | |
</div> | |
<script id="jsbin-javascript"> | |
const regexAliases = /@(.+?[a-z0-9_.\-+]+)/gi; | |
let textInput = document.getElementById('text'); | |
let result = document.getElementById('result'); | |
const aliases = { | |
raul: { | |
name: 'Raul Lucero' | |
}, | |
alejandro: { | |
name: 'Alejandro Medina' | |
} | |
} | |
const button = document.getElementById('button'); | |
button.addEventListener('click', (e) => { | |
console.log(textInput.value); | |
const text = textInput.value.replace(regexAliases, function (str, p1, _index, offset, s) { | |
if (!!aliases[p1]) { | |
return '<b>' + aliases[p1].name + '</b>'; | |
} | |
return str; | |
}); | |
result.innerHTML = text; | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const regexAliases = /@(.+?[a-z0-9_.\-+]+)/gi; | |
let textInput = document.getElementById('text'); | |
let result = document.getElementById('result'); | |
const aliases = { | |
raul: { | |
name: 'Raul Lucero' | |
}, | |
alejandro: { | |
name: 'Alejandro Medina' | |
} | |
} | |
const button = document.getElementById('button'); | |
button.addEventListener('click', (e) => { | |
console.log(textInput.value); | |
const text = textInput.value.replace(regexAliases, function (str, p1, _index, offset, s) { | |
if (!!aliases[p1]) { | |
return '<b>' + aliases[p1].name + '</b>'; | |
} | |
return str; | |
}); | |
result.innerHTML = text; | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regexAliases = /@(.+?[a-z0-9_.\-+]+)/gi; | |
let textInput = document.getElementById('text'); | |
let result = document.getElementById('result'); | |
const aliases = { | |
raul: { | |
name: 'Raul Lucero' | |
}, | |
alejandro: { | |
name: 'Alejandro Medina' | |
} | |
} | |
const button = document.getElementById('button'); | |
button.addEventListener('click', (e) => { | |
console.log(textInput.value); | |
const text = textInput.value.replace(regexAliases, function (str, p1, _index, offset, s) { | |
if (!!aliases[p1]) { | |
return '<b>' + aliases[p1].name + '</b>'; | |
} | |
return str; | |
}); | |
result.innerHTML = text; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use it for a mencion method