I use preg_match to the program like this
if (preg_match('/^[a-z0-9]+\:/{1,2}', $filename))
But it shows an error like this
Warning: preg_match() [function.preg-match]: Unknown modifier '{'
how to change this?
You are missing '/' at the end of the regex and you should escape '/' in the regex itself. This should work i.e. warning should be gone (ignoring if regex you've written is doing what you want):
if (preg_match('/^[a-z0-9]+\:\/{1,2}/', $filename))
Related
When trying to deploy to heroku I get the following error:
rake aborted!
Uglifier::Error: Unexpected character '“'
I have modified the production.rb to include config.assets.js_compressor = Uglifier.new(harmony: true) instead of config.assets.js_compressor = :uglifier
It seems you have used a typographic (or "smart") quote character somewhere in your code as opposed to a normal " character. Depending on your font, they might look very similar but are different characters, resulting in the error you have seen there.
To resolve this, you should search all of your code and replace all mentions of the “ character with ".
For code
url.gsub(/"|\[|]| /, '')
ruby raises warning
warning: regular expression has ']' without escape: /"|\[|]| /
How to fix it?
Your regex would be reduced to,
url.gsub(/[ "\[\]]/, '')
I am a newbie in Ruby, I'm using version 1.9.3. I have the following regular expression:
/\\\//
As far as I know, it should match a string which has the characters '\' and '/', one following the other, right?
I am using the following code in order to get true in case the regex matches the string or symbol in the far right:
!(regex !~ :"string or symbol to match")
Because using =~ gives me the index of the match and I simply want a boolean. Besides, I'm trying to see how ugly or hackish can Ruby look compared to C :P
When I try to match the symbol :\/ the IRB prompt changes to an asterisk, and returns nothing. Why?
When I try to match the string "\/" my little ugly snippet returns false. Why?
The symbol :\/ is not a valid symbol. You could do :'\/' if you wanted a symbol version of the string '\/'. And when you feed it "\/" it is false because that has double quotes so it is actually the string '/' so you actually want either '\/' or "\\/".
Finally, it's better code and convention to do your test like so:
!!(regex =~ :'\/')
!!(regex =~ '\/')
!!(regex =~ "\\/")
I tried using a regular expression to capture names:
r[1].scan(/^([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞıİçÇöÖüÜĞğ])*\s([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞıİçÇöÖüÜĞğ])*/u)
But, it gives me an error:
syntax error, unexpected $end, expecting ')'
...atches = r[1].scan(/^([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞ�...
...
I see that the problem is the Turkish characters I'm using. Is it possible to use unicode values of the characters in regexp? How can I use these problematic characters in this regexp?
Use ruby 1.9
Go with /\p{Word}+\p{Space}\p{Word}*/
I have deprecated "eregi" problem.
if (eregi("data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)", $edit_img, $tmp))
So I changed into this,
if (preg_match("/data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)/i", $edit_img,$tmp))
But I got new warmingmessage,
Warning: preg_match() [function.preg-match]: Unknown modifier 'c'
Please let me know what is wrong.
Thanks in advance.
You have a '/' inside your regex ('data/cheditor') but you are also using '/' as the regex delimiter ('/myregex/flags'): you can either escape the internal '/', or use a different regex delimiter.
E.g. first option:
preg_match('/data\/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)/i',...
or (second option, I chose '#' as the delimiter):
preg_match('#data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)#i',...
Also note I changed the " around your regex to ' because otherwise you need to double the backslashes within double-quotes in PHP.