• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

Posts tagged contain

Javascript> Check if string contains VARIABLE

Oct26
2010
Written by Scott Rowley

Just a bit of code to help you find whether or not a certain word/phrase/letter/number/whatever is present in something like a form entry.

if (TEXT.match(/b<VARIABLE>b/i) != null) {
alert(true);
}

For instance, I have a domain registration form and we know there are no spaces allowed in domain names, so:

if (TEXT.match(/b b/i) != null) {
alert(true);
}
Posted in Javascript, Web Development - Tagged alert, Javascript, string, variable

BASH> if ARRAY [does not] contains string

Oct26
2010
Written by Scott Rowley

Check if an array contains a given string:

teams=(chiefs broncos chargers raiders)
if [[ ${teams[*]} =~ broncos ]]
then
echo "VICTORY!"
fi

Or, if you don’t want it to contain the string then:

teams=(cardinals 49ers seahawks rams)
if [[ ${teams[*]} =~ broncos ]]
then
echo "This conference sucks"
else
echo "VICTORY!"
fi
Posted in BASH - Tagged array, BASH, string

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top