Rails 3: Validate IP String
In Rails 3, is there a built in method for seeing if a string is a valid IP address? If not, what is the easiest way to validate? ...
In Rails 3, is there a built in method for seeing if a string is a valid IP address? If not, what is the easiest way to validate? ...
My URL's might not be well formatted, so it could be http://www.google.com/ or www.google.com or google.com and it'll be in a block of text like: This is google.com and it rocks! I need to find the website and replace it with [*********] Any ideas? ...
Im setting up a simple checker program thing. For now, its extremely simple and is jsut checking integers. I dont think the regular expressions are wrong, but I am new to ruby. testing out the auto-regex def createRegexClosure(re) reg = Regexp.new(re) return lambda { |t| return reg.match(t) } end pr...
Hi, I have juste a little experience with the regex, and now I have a little problem. I must retrieve the strings between the . So here is a sample : Categories: <a href="/car/2/page1.html">2</a>, <a href="/car/nissan/">nissan</a>,<a href="/car/all/page1.html">all</a> And this is my little regex: re.findall("""<a href=".*">.*</a>"...
How could I search for a word in a certain file, and then replace that word with a different string of text. Like for example: In this paragraph find the word iPad and replace it with iPhone. I would like a code sample in C (or C++ if it is not possible without a third party library). ...
I am trying to rename multiple files in windows using powershell. And I want to rename replacing this pattern: "123456-the_other_part_of_the_string". Example: 409873-doc1.txt 378234-doc2.txt 1230-doc3.txt Basically I want to crop the numbers + '-' thing. ...
Hello, First of all I created my own regex to find all URLs in a text, because: When I searched SO and google only found regex for specific URL constructions, like images, etc. I found a pretty complete regex from the PHP's manual itself (see "splattermania at freenet dot de 01-Oct-2009 12:01" post at http://php.net/manual/en/function...
When running my Javascript through JSLint, I get the following two errors from the same line of code. Problem at line 398 character 29: Insecure '.'. if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) Problem at line 398 character 41: Unescaped '^'. if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) I understand that JSLint m...
Ok say I have a string in python: str="martin added 1 new photo to the <a href=''>martins photos</a> album." the string contains a lot more css/html in real world use What is the fastest way to change the 1 ('1 new photo') to say '2 new photos'. of course later the '1' may say '12'. Note, I don't know what the number is, so doing a r...
I'm generating text images using imagemagick by passing user inputs via command. I'm concerned that a user could enter something malicious. # regex pattern [^\s\w\.&!?"] # image generation code, in Ruby "convert -quality 100 -background black -fill red -font Times-Bold -size x50 label:'#{@line1}' output.jpg" ...
Hi, I currently have a coldfusion regex that checks whether a string is alphanumeric or not. I would like to open that up a bit more to allow period and underscore characters. How would I modify this to allow that? <cfset isValid= true/> <cfif REFind("[^[:alnum:]]", arguments.stringToCheck, 1) GT 0> <cfset isValid= false /> </cfif> ...
A colleague of mine is using a horrible source code editor that leaves strange comments all over the code. In Visual Studio, I created a macro, that simply folds all those comment blocks so I don't have to see them. Now I would like to do the very same thing in vim. This regex matches every one of those blocks: /^.*\/\* EasyCODE.*\(\(...
How to search for occurences of more than one space between words in a line 1. this is a line containing 2 spaces 2. this is a line containing 3 spaces 3. this is a line containg multiple spaces first second three four All the above are valid matches for this regex. What regex should I use? ...
I'm writing a method that should extract the fully qualified class name out of a java.lang.reflect.Method-object. As i could not find any convenience method to get the classname of a Method-object, i'm trying to extract it with the following Regex-expression: ([A-Za-z.]*)[\(] (maybe there's also a way without a Regex?). public String...
I want to select records if a particular column has numbers in its name. Table 1 ID EmpCode EmpName 1 1C Name1 2 2C Name2 3 C3 Name3 4 CD Name4 5 CD Name4 6 C6D Name6 7 7CD Name7 I need to select records 1,2,3,6,7 based on EmpCode. How can this be pe...
Hi, I'm using Symfony 1.4 and am a little stuck regarding form validation. I have a validator like the one below: $this->setValidator('mobile_number', new sfValidatorAnd(array( new sfValidatorString(array('max_length' => 13)), new sfValidatorRegex(array('pattern' => '/^07\d{9}$/'), array('invalid' => 'Invalid mobile number.'...
I want match my @array = ( 'Tree' , 'JoeTree'); foreach (@array ) { if ( $_ =~ /^(Joe)Tree/gi) { print "matched $_"; } } It matching only JoeTree. It's not matching Tree ? ...
Given the output of dmidecode Handle 0x0025, DMI type 13, 22 bytes BIOS Language Information Installable Languages: 1 en|US|iso8859-1 Currently Installed Language: en|US|iso8859-1 Handle 0x0026, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Sing...
How to split the string "Thequickbrownfoxjumps" to substrings of equal size in Java. Eg. "Thequickbrownfoxjumps" of 4 equal size should give the output. ["Theq","uick","brow","nfox","jump","s"] Similar Question: Split string into equal-length substrings in Scala ...
$string = " put returns between paragraphs for linebreak add 2 spaces at end "; Want to remove all new lines from string. I've this regex, it can catch all of them, the problem is I don't know with which function should I use it. /\r\n|\r|\n/ $string should become: $string = "put returns between paragraphs for linebreak add 2 sp...