Using String Format to show decimal up to 2 places or simple integer

Sorry for reactivating this question, but I didn’t find the right answer here. In formatting numbers you can use 0 as a mandatory place and # as an optional place. So: // just two decimal places String.Format(“{0:0.##}”, 123.4567); // “123.46” String.Format(“{0:0.##}”, 123.4); // “123.4” String.Format(“{0:0.##}”, 123.0); // “123” You can also combine 0 with #. … Read more

Remove all special characters, punctuation and spaces from string

This can be done without regex: >>> string = “Special $#! characters spaces 888323″ >>> ”.join(e for e in string if e.isalnum()) ‘Specialcharactersspaces888323’ You can use str.isalnum: S.isalnum() -> bool Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. If you insist on using … Read more

Regular expression to match balanced parentheses

I want to add this answer for quickreference. Feel free to update. .NET Regex using balancing groups. \((?>\((?<c>)|[^()]+|\)(?<-c>))*(?(c)(?!))\) Where c is used as the depth counter. Demo at Regexstorm.com Stack Overflow: Using RegEx to balance match parenthesis Wes’ Puzzling Blog: Matching Balanced Constructs with .NET Regular Expressions Greg Reinacker’s Weblog: Nested Constructs in Regular Expressions … Read more

How to use regex with find command?

find . -regextype sed -regex “.*/[a-f0-9\-]\{36\}\.jpg” Note that you need to specify .*/ in the beginning because find matches the whole path. Example: susam@nifty:~/so$ find . -name “*.jpg” ./foo-111.jpg ./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg ./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg susam@nifty:~/so$ susam@nifty:~/so$ find . -regextype sed -regex “.*/[a-f0-9\-]\{36\}\.jpg” ./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg ./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg My version of find: $ find –version find (GNU findutils) 4.4.2 Copyright (C) 2007 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)