OM2 Posted August 21, 2011 Share Posted August 21, 2011 OK... so this isn't actually a PHP coding answer But... I'm guessing the answer that works for PHP, will work for my purpose Sometimes, I need to search for text containing special characters In this instance, I'm trying to use Wingrep to search for all files that contains '$myVariable' Is there a standard way of escaping the meaning of $? Thanks in advance OM Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/ Share on other sites More sharing options...
cssfreakie Posted August 21, 2011 Share Posted August 21, 2011 inside double quotes and a heredoc a backslash would suffice for instance: echo "lalala this \$variable will not work"; inside single quotes $ has no meaning Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260023 Share on other sites More sharing options...
JAY6390 Posted August 21, 2011 Share Posted August 21, 2011 Since this is in the regex section I'm guessing it's related to regexes The answer is still the backslash \$ will escape a $, however you will also need to escape the \ in a string so it would actually be "/\\$/" for example Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260098 Share on other sites More sharing options...
OM2 Posted August 21, 2011 Author Share Posted August 21, 2011 that didn't quite work - my guess was that it would do i found the solution anyway - there's an option where u can choose to 'not us' regular expressions - i can now search for strings that have $ in thanks for the reply - much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260137 Share on other sites More sharing options...
OM2 Posted August 21, 2011 Author Share Posted August 21, 2011 Since this is in the regex section I'm guessing it's related to regexes The answer is still the backslash \$ will escape a $, however you will also need to escape the \ in a string so it would actually be "/\\$/" for example i tried this - didn't work though i think i must be doing something wrong the use of searches and regular expressions should be the same as used for php or perl (i assumed - hence i asked my question here) thanks Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260139 Share on other sites More sharing options...
cags Posted August 22, 2011 Share Posted August 22, 2011 It's almost certainly to do with escaping of the string. Depending on how you are running the search you probably just need more slashes. In pure regex \$ will match a dollar sign. But if you are using that in a command line tool, you likely have to escape the slash for that too. You can easily end up with strings requiring 4 slashes in order to escape them correctly to allow the correct number to make it through to the actual regex parser. Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260409 Share on other sites More sharing options...
salathe Posted August 22, 2011 Share Posted August 22, 2011 though i think i must be doing something wrong You must be. Wingrep happily searches for literal dollar characters with \$ Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260472 Share on other sites More sharing options...
OM2 Posted August 22, 2011 Author Share Posted August 22, 2011 using wingrep ok... my bad... it works i thought i had tried that before - obviously not thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/245326-how-do-i-search-for-the-character/#findComment-1260478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.